mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 15:30:25 +08:00
refactor: 代码优化与数据库表列显示配置优化
This commit is contained in:
@@ -1,51 +1,53 @@
|
||||
<template>
|
||||
<div class="w100" style="border: 1px solid var(--el-border-color)">
|
||||
<el-input v-model="filterTag" clearable placeholder="输入关键字过滤" size="small" />
|
||||
<el-scrollbar :style="{ height: props.height }">
|
||||
<el-tree
|
||||
v-bind="$attrs"
|
||||
ref="tagTreeRef"
|
||||
style="width: 100%"
|
||||
:data="state.tags"
|
||||
:default-expanded-keys="checkedTags"
|
||||
:default-checked-keys="checkedTags"
|
||||
multiple
|
||||
:render-after-expand="true"
|
||||
show-checkbox
|
||||
check-strictly
|
||||
:node-key="$props.nodeKey"
|
||||
:props="{
|
||||
value: $props.nodeKey,
|
||||
label: 'codePath',
|
||||
children: 'children',
|
||||
disabled: 'disabled',
|
||||
}"
|
||||
@check="tagTreeNodeCheck"
|
||||
:filter-node-method="filterNode"
|
||||
>
|
||||
<template #default="{ data }">
|
||||
<span class="custom-tree-node">
|
||||
<SvgIcon
|
||||
:name="EnumValue.getEnumByValue(TagResourceTypeEnum, data.type)?.extra.icon"
|
||||
:color="EnumValue.getEnumByValue(TagResourceTypeEnum, data.type)?.extra.iconColor"
|
||||
/>
|
||||
<div class="w100">
|
||||
<el-input v-model="filterTag" @input="onFilterValChanged" clearable placeholder="输入关键字过滤" size="small" />
|
||||
<div class="mt3" style="border: 1px solid var(--el-border-color)">
|
||||
<el-scrollbar :style="{ height: props.height }">
|
||||
<el-tree
|
||||
v-bind="$attrs"
|
||||
ref="tagTreeRef"
|
||||
style="width: 100%"
|
||||
:data="state.tags"
|
||||
:default-expanded-keys="checkedTags"
|
||||
:default-checked-keys="checkedTags"
|
||||
multiple
|
||||
:render-after-expand="true"
|
||||
show-checkbox
|
||||
check-strictly
|
||||
:node-key="$props.nodeKey"
|
||||
:props="{
|
||||
value: $props.nodeKey,
|
||||
label: 'codePath',
|
||||
children: 'children',
|
||||
disabled: 'disabled',
|
||||
}"
|
||||
@check="tagTreeNodeCheck"
|
||||
:filter-node-method="filterNode"
|
||||
>
|
||||
<template #default="{ data }">
|
||||
<span class="custom-tree-node">
|
||||
<SvgIcon
|
||||
:name="EnumValue.getEnumByValue(TagResourceTypeEnum, data.type)?.extra.icon"
|
||||
:color="EnumValue.getEnumByValue(TagResourceTypeEnum, data.type)?.extra.iconColor"
|
||||
/>
|
||||
|
||||
<span class="font13 ml5">
|
||||
{{ data.code }}
|
||||
<span style="color: #3c8dbc">【</span>
|
||||
{{ data.name }}
|
||||
<span style="color: #3c8dbc">】</span>
|
||||
<el-tag v-if="data.children !== null" size="small">{{ data.children.length }} </el-tag>
|
||||
<span class="font13 ml5">
|
||||
{{ data.code }}
|
||||
<span style="color: #3c8dbc">【</span>
|
||||
{{ data.name }}
|
||||
<span style="color: #3c8dbc">】</span>
|
||||
<el-tag v-if="data.children !== null" size="small">{{ data.children.length }} </el-tag>
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
</el-scrollbar>
|
||||
</template>
|
||||
</el-tree>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, onMounted, watch } from 'vue';
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { tagApi } from '../tag/api';
|
||||
import { TagResourceTypeEnum } from '@/common/commonEnum';
|
||||
import EnumValue from '@/common/Enum';
|
||||
@@ -98,10 +100,6 @@ const search = async () => {
|
||||
}, 200);
|
||||
};
|
||||
|
||||
watch(filterTag, (val) => {
|
||||
tagTreeRef.value!.filter(val);
|
||||
});
|
||||
|
||||
const filterNode = (value: string, data: any) => {
|
||||
if (!value) {
|
||||
return true;
|
||||
@@ -109,6 +107,10 @@ const filterNode = (value: string, data: any) => {
|
||||
return data.codePath.toLowerCase().includes(value) || data.name.includes(value);
|
||||
};
|
||||
|
||||
const onFilterValChanged = (val: string) => {
|
||||
tagTreeRef.value!.filter(val);
|
||||
};
|
||||
|
||||
const tagTreeNodeCheck = (data: any) => {
|
||||
const node = tagTreeRef.value.getNode(data.codePath);
|
||||
console.log('check node: ', node);
|
||||
|
||||
@@ -199,3 +199,16 @@ export function getTagTypeCodeByPath(codePath: string) {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function expandCodePath(codePath: string) {
|
||||
const parts = codePath.split('/');
|
||||
const result = [];
|
||||
let currentPath = '';
|
||||
|
||||
for (let i = 0; i < parts.length - 1; i++) {
|
||||
currentPath += parts[i] + '/';
|
||||
result.push(currentPath);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -13,14 +13,27 @@
|
||||
title="表格字段配置"
|
||||
trigger="click"
|
||||
>
|
||||
<div v-for="(item, index) in columns" :key="index">
|
||||
<div><el-input v-model="checkedShowColumns.searchKey" size="small" placeholder="输入列名或备注过滤" /></div>
|
||||
<div>
|
||||
<el-checkbox
|
||||
v-model="item.show"
|
||||
:label="`${!item.columnComment ? item.columnName : item.columnName + ' [' + item.columnComment + ']'}`"
|
||||
:true-value="true"
|
||||
:false-value="false"
|
||||
v-model="checkedShowColumns.checkedAllColumn"
|
||||
:indeterminate="checkedShowColumns.isIndeterminate"
|
||||
@change="handleCheckAllColumnChange"
|
||||
size="small"
|
||||
/>
|
||||
>
|
||||
选择所有
|
||||
</el-checkbox>
|
||||
|
||||
<el-checkbox-group v-model="checkedShowColumns.columnNames" @change="handleCheckedColumnChange">
|
||||
<div v-for="(item, index) in filterCheckedColumns" :key="index">
|
||||
<el-checkbox
|
||||
:key="index"
|
||||
:label="`${!item.columnComment ? item.columnName : item.columnName + ' [' + item.columnComment + ']'}`"
|
||||
:value="item.columnName"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
<template #reference>
|
||||
<el-link icon="Operation" size="small" :underline="false"></el-link>
|
||||
@@ -329,9 +342,17 @@ const state = reactive({
|
||||
tableHeight: '600px',
|
||||
hasUpdatedFileds: false,
|
||||
dbDialect: {} as DbDialect,
|
||||
|
||||
checkedShowColumns: {
|
||||
searchKey: '',
|
||||
checkedAllColumn: true,
|
||||
isIndeterminate: false,
|
||||
columnNames: [] as any,
|
||||
},
|
||||
});
|
||||
|
||||
const { datas, condition, loading, columns, pageNum, pageSize, pageSizes, sql, hasUpdatedFileds, conditionDialog, addDataDialog } = toRefs(state);
|
||||
const { datas, condition, loading, columns, checkedShowColumns, pageNum, pageSize, pageSizes, sql, hasUpdatedFileds, conditionDialog, addDataDialog } =
|
||||
toRefs(state);
|
||||
|
||||
watch(
|
||||
() => props.tableHeight,
|
||||
@@ -351,6 +372,8 @@ onMounted(async () => {
|
||||
|
||||
state.dbDialect = getNowDbInst().getDialect();
|
||||
useEventListener('click', handlerWindowClick);
|
||||
|
||||
state.checkedShowColumns.columnNames = state.columns.map((item: any) => item.columnName);
|
||||
});
|
||||
|
||||
const handlerWindowClick = () => {
|
||||
@@ -414,6 +437,7 @@ const handleSetPageNum = async () => {
|
||||
state.pageNum = state.setPageNum;
|
||||
await selectData();
|
||||
};
|
||||
|
||||
const handleCount = async () => {
|
||||
state.counting = true;
|
||||
|
||||
@@ -431,6 +455,26 @@ const handleCount = async () => {
|
||||
state.counting = false;
|
||||
};
|
||||
|
||||
const handleCheckAllColumnChange = (val: boolean) => {
|
||||
state.checkedShowColumns.columnNames = val ? state.columns.map((x: any) => x.columnName) : [];
|
||||
state.checkedShowColumns.isIndeterminate = false;
|
||||
triggerCheckedColumns();
|
||||
};
|
||||
|
||||
const handleCheckedColumnChange = (value: string[]) => {
|
||||
const checkedCount = value.length;
|
||||
state.checkedShowColumns.checkedAllColumn = checkedCount === state.columns.length;
|
||||
state.checkedShowColumns.isIndeterminate = checkedCount > 0 && checkedCount < state.columns.length;
|
||||
triggerCheckedColumns();
|
||||
};
|
||||
|
||||
const triggerCheckedColumns = () => {
|
||||
const checkedColumnNames = state.checkedShowColumns.columnNames;
|
||||
for (let column of state.columns) {
|
||||
column.show = checkedColumnNames.includes(column.columnName);
|
||||
}
|
||||
};
|
||||
|
||||
// 完整的条件,每次选中后会重置条件框内容,故需要这个变量在获取建议时将文本框内容保存
|
||||
let completeCond = '';
|
||||
// 是否存在列建议
|
||||
@@ -490,16 +534,23 @@ const chooseCondColumnName = () => {
|
||||
* 过滤条件列名
|
||||
*/
|
||||
const filterCondColumns = computed(() => {
|
||||
return filterColumns(state.columnNameSearch);
|
||||
});
|
||||
|
||||
const filterCheckedColumns = computed(() => {
|
||||
return filterColumns(state.checkedShowColumns.searchKey);
|
||||
});
|
||||
|
||||
const filterColumns = (searchKey: string) => {
|
||||
const columns = state.columns;
|
||||
let columnNameSearch = state.columnNameSearch;
|
||||
if (!columnNameSearch) {
|
||||
if (!searchKey) {
|
||||
return columns;
|
||||
}
|
||||
columnNameSearch = columnNameSearch.toLowerCase();
|
||||
searchKey = searchKey.toLowerCase();
|
||||
return columns.filter((data: any) => {
|
||||
return data.columnName.toLowerCase().includes(columnNameSearch) || data.columnComment.toLowerCase().includes(columnNameSearch);
|
||||
return data.columnName.toLowerCase().includes(searchKey) || data.columnComment.toLowerCase().includes(searchKey);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 条件查询,点击列信息后显示输入对应的值
|
||||
|
||||
@@ -195,6 +195,9 @@ const contextmenuAdd = new ContextmenuItem('addTag', '添加子标签')
|
||||
const contextmenuEdit = new ContextmenuItem('edit', '编辑')
|
||||
.withIcon('edit')
|
||||
.withPermission('tag:save')
|
||||
.withHideFunc((data: any) => {
|
||||
return data.type != TagResourceTypeEnum.Tag.value;
|
||||
})
|
||||
.withOnClick((data: any) => showEditTagDialog(data));
|
||||
|
||||
const contextmenuDel = new ContextmenuItem('delete', '删除')
|
||||
@@ -376,6 +379,11 @@ const search = async () => {
|
||||
state.data = res;
|
||||
};
|
||||
|
||||
const getDetail = async (id: number) => {
|
||||
const tags = await tagApi.listByQuery.request({ id });
|
||||
return tags?.[0];
|
||||
};
|
||||
|
||||
// 树节点右击事件
|
||||
const nodeContextmenu = (event: any, data: any) => {
|
||||
const { clientX, clientY } = event;
|
||||
@@ -384,8 +392,8 @@ const nodeContextmenu = (event: any, data: any) => {
|
||||
contextmenuRef.value.openContextmenu(data);
|
||||
};
|
||||
|
||||
const treeNodeClick = (data: any) => {
|
||||
state.currentTag = data;
|
||||
const treeNodeClick = async (data: any) => {
|
||||
state.currentTag = await getDetail(data.id);
|
||||
// 关闭可能存在的右击菜单
|
||||
contextmenuRef.value.closeContextmenu();
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"mayfly-go/internal/db/api/form"
|
||||
"mayfly-go/internal/db/api/vo"
|
||||
"mayfly-go/internal/db/application"
|
||||
"mayfly-go/internal/db/application/dto"
|
||||
"mayfly-go/internal/db/config"
|
||||
"mayfly-go/internal/db/dbm/dbi"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
@@ -304,7 +305,7 @@ func (d *Db) DumpSql(rc *req.Ctx) {
|
||||
}
|
||||
}()
|
||||
|
||||
biz.ErrIsNil(d.DbApp.DumpDb(rc.MetaCtx, &application.DumpDbReq{
|
||||
biz.ErrIsNil(d.DbApp.DumpDb(rc.MetaCtx, &dto.DumpDb{
|
||||
DbId: dbId,
|
||||
DbName: dbName,
|
||||
Tables: tables,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"mayfly-go/internal/db/api/form"
|
||||
"mayfly-go/internal/db/api/vo"
|
||||
"mayfly-go/internal/db/application"
|
||||
"mayfly-go/internal/db/application/dto"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
@@ -70,7 +71,7 @@ func (d *Instance) SaveInstance(rc *req.Ctx) {
|
||||
instance := req.BindJsonAndCopyTo[*entity.DbInstance](rc, form, new(entity.DbInstance))
|
||||
|
||||
rc.ReqParam = form
|
||||
id, err := d.InstanceApp.SaveDbInstance(rc.MetaCtx, &application.SaveDbInstanceParam{
|
||||
id, err := d.InstanceApp.SaveDbInstance(rc.MetaCtx, &dto.SaveDbInstance{
|
||||
DbInstance: instance,
|
||||
AuthCerts: form.AuthCerts,
|
||||
TagCodePaths: form.TagCodePaths,
|
||||
|
||||
@@ -3,11 +3,13 @@ package application
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mayfly-go/internal/db/application/dto"
|
||||
"mayfly-go/internal/db/dbm"
|
||||
"mayfly-go/internal/db/dbm/dbi"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
tagdto "mayfly-go/internal/tag/application/dto"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/biz"
|
||||
@@ -40,7 +42,7 @@ type Db interface {
|
||||
GetDbConnByInstanceId(instanceId uint64) (*dbi.DbConn, error)
|
||||
|
||||
// DumpDb dumpDb
|
||||
DumpDb(ctx context.Context, reqParam *DumpDbReq) error
|
||||
DumpDb(ctx context.Context, reqParam *dto.DumpDb) error
|
||||
}
|
||||
|
||||
type dbAppImpl struct {
|
||||
@@ -53,6 +55,8 @@ type dbAppImpl struct {
|
||||
resourceAuthCertApp tagapp.ResourceAuthCert `inject:"ResourceAuthCertApp"`
|
||||
}
|
||||
|
||||
var _ (Db) = (*dbAppImpl)(nil)
|
||||
|
||||
// 注入DbRepo
|
||||
func (d *dbAppImpl) InjectDbRepo(repo repository.Db) {
|
||||
d.Repo = repo
|
||||
@@ -86,8 +90,8 @@ func (d *dbAppImpl) SaveDb(ctx context.Context, dbEntity *entity.Db) error {
|
||||
return d.Insert(ctx, dbEntity)
|
||||
}, func(ctx context.Context) error {
|
||||
// 将库关联至指定数据库授权凭证下
|
||||
return d.tagApp.RelateTagsByCodeAndType(ctx, &tagapp.RelateTagsByCodeAndTypeParam{
|
||||
Tags: []*tagapp.ResourceTag{{
|
||||
return d.tagApp.RelateTagsByCodeAndType(ctx, &tagdto.RelateTagsByCodeAndType{
|
||||
Tags: []*tagdto.ResourceTag{{
|
||||
Code: dbEntity.Code,
|
||||
Type: tagentity.TagTypeDbName,
|
||||
Name: dbEntity.Name,
|
||||
@@ -163,7 +167,7 @@ func (d *dbAppImpl) Delete(ctx context.Context, id uint64) error {
|
||||
}, func(ctx context.Context) error {
|
||||
return d.dbSqlExecApp.DeleteBy(ctx, &entity.DbSqlExec{DbId: id})
|
||||
}, func(ctx context.Context) error {
|
||||
return d.tagApp.DeleteTagByParam(ctx, &tagapp.DelResourceTagParam{
|
||||
return d.tagApp.DeleteTagByParam(ctx, &tagdto.DelResourceTag{
|
||||
ResourceCode: db.Code,
|
||||
ResourceType: tagentity.TagTypeDbName,
|
||||
})
|
||||
@@ -217,7 +221,7 @@ func (d *dbAppImpl) GetDbConnByInstanceId(instanceId uint64) (*dbi.DbConn, error
|
||||
return d.GetDbConn(firstDb.Id, strings.Split(firstDb.Database, " ")[0])
|
||||
}
|
||||
|
||||
func (d *dbAppImpl) DumpDb(ctx context.Context, reqParam *DumpDbReq) error {
|
||||
func (d *dbAppImpl) DumpDb(ctx context.Context, reqParam *dto.DumpDb) error {
|
||||
writer := newGzipWriter(reqParam.Writer)
|
||||
defer writer.Close()
|
||||
dbId := reqParam.DbId
|
||||
|
||||
@@ -4,11 +4,13 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"mayfly-go/internal/common/consts"
|
||||
"mayfly-go/internal/db/application/dto"
|
||||
"mayfly-go/internal/db/dbm"
|
||||
"mayfly-go/internal/db/dbm/dbi"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
tagdto "mayfly-go/internal/tag/application/dto"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/biz"
|
||||
@@ -21,12 +23,6 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SaveDbInstanceParam struct {
|
||||
DbInstance *entity.DbInstance
|
||||
AuthCerts []*tagentity.ResourceAuthCert
|
||||
TagCodePaths []string
|
||||
}
|
||||
|
||||
type Instance interface {
|
||||
base.App[*entity.DbInstance]
|
||||
|
||||
@@ -35,7 +31,7 @@ type Instance interface {
|
||||
|
||||
TestConn(instanceEntity *entity.DbInstance, authCert *tagentity.ResourceAuthCert) error
|
||||
|
||||
SaveDbInstance(ctx context.Context, instance *SaveDbInstanceParam) (uint64, error)
|
||||
SaveDbInstance(ctx context.Context, instance *dto.SaveDbInstance) (uint64, error)
|
||||
|
||||
// Delete 删除数据库信息
|
||||
Delete(ctx context.Context, id uint64) error
|
||||
@@ -91,7 +87,7 @@ func (app *instanceAppImpl) TestConn(instanceEntity *entity.DbInstance, authCert
|
||||
return nil
|
||||
}
|
||||
|
||||
func (app *instanceAppImpl) SaveDbInstance(ctx context.Context, instance *SaveDbInstanceParam) (uint64, error) {
|
||||
func (app *instanceAppImpl) SaveDbInstance(ctx context.Context, instance *dto.SaveDbInstance) (uint64, error) {
|
||||
instanceEntity := instance.DbInstance
|
||||
// 默认tcp连接
|
||||
instanceEntity.Network = instanceEntity.GetNetwork()
|
||||
@@ -128,7 +124,7 @@ func (app *instanceAppImpl) SaveDbInstance(ctx context.Context, instance *SaveDb
|
||||
AuthCerts: authCerts,
|
||||
})
|
||||
}, func(ctx context.Context) error {
|
||||
return app.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
return app.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: app.genDbInstanceResourceTag(instanceEntity, authCerts),
|
||||
ParentTagCodePaths: tagCodePaths,
|
||||
})
|
||||
@@ -162,7 +158,7 @@ func (app *instanceAppImpl) SaveDbInstance(ctx context.Context, instance *SaveDb
|
||||
return err
|
||||
}
|
||||
}
|
||||
return app.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
return app.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: app.genDbInstanceResourceTag(instanceEntity, authCerts),
|
||||
ParentTagCodePaths: tagCodePaths,
|
||||
})
|
||||
@@ -214,7 +210,7 @@ func (app *instanceAppImpl) Delete(ctx context.Context, instanceId uint64) error
|
||||
ResourceType: tagentity.TagType(consts.ResourceTypeDb),
|
||||
})
|
||||
}, func(ctx context.Context) error {
|
||||
return app.tagApp.DeleteTagByParam(ctx, &tagapp.DelResourceTagParam{
|
||||
return app.tagApp.DeleteTagByParam(ctx, &tagdto.DelResourceTag{
|
||||
ResourceCode: instance.Code,
|
||||
ResourceType: tagentity.TagType(consts.ResourceTypeDb),
|
||||
})
|
||||
@@ -275,9 +271,9 @@ func (app *instanceAppImpl) toDbInfoByAc(instance *entity.DbInstance, ac *tagent
|
||||
return di
|
||||
}
|
||||
|
||||
func (m *instanceAppImpl) genDbInstanceResourceTag(me *entity.DbInstance, authCerts []*tagentity.ResourceAuthCert) *tagapp.ResourceTag {
|
||||
authCertTags := collx.ArrayMap[*tagentity.ResourceAuthCert, *tagapp.ResourceTag](authCerts, func(val *tagentity.ResourceAuthCert) *tagapp.ResourceTag {
|
||||
return &tagapp.ResourceTag{
|
||||
func (m *instanceAppImpl) genDbInstanceResourceTag(me *entity.DbInstance, authCerts []*tagentity.ResourceAuthCert) *tagdto.ResourceTag {
|
||||
authCertTags := collx.ArrayMap[*tagentity.ResourceAuthCert, *tagdto.ResourceTag](authCerts, func(val *tagentity.ResourceAuthCert) *tagdto.ResourceTag {
|
||||
return &tagdto.ResourceTag{
|
||||
Code: val.Name,
|
||||
Name: val.Username,
|
||||
Type: tagentity.TagTypeDbAuthCert,
|
||||
@@ -291,9 +287,9 @@ func (m *instanceAppImpl) genDbInstanceResourceTag(me *entity.DbInstance, authCe
|
||||
logx.Errorf("获取实例关联的数据库失败: %v", err)
|
||||
}
|
||||
|
||||
authCertName2DbTags := make(map[string][]*tagapp.ResourceTag)
|
||||
authCertName2DbTags := make(map[string][]*tagdto.ResourceTag)
|
||||
for _, db := range dbs {
|
||||
authCertName2DbTags[db.AuthCertName] = append(authCertName2DbTags[db.AuthCertName], &tagapp.ResourceTag{
|
||||
authCertName2DbTags[db.AuthCertName] = append(authCertName2DbTags[db.AuthCertName], &tagdto.ResourceTag{
|
||||
Code: db.Code,
|
||||
Name: db.Name,
|
||||
Type: tagentity.TagTypeDbName,
|
||||
@@ -305,7 +301,7 @@ func (m *instanceAppImpl) genDbInstanceResourceTag(me *entity.DbInstance, authCe
|
||||
ac.Children = authCertName2DbTags[ac.Code]
|
||||
}
|
||||
|
||||
return &tagapp.ResourceTag{
|
||||
return &tagdto.ResourceTag{
|
||||
Code: me.Code,
|
||||
Type: tagentity.TagTypeDb,
|
||||
Name: me.Name,
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
"mayfly-go/internal/db/domain/repository"
|
||||
flowapp "mayfly-go/internal/flow/application"
|
||||
flowdto "mayfly-go/internal/flow/application/dto"
|
||||
flowentity "mayfly-go/internal/flow/domain/entity"
|
||||
"mayfly-go/pkg/contextx"
|
||||
"mayfly-go/pkg/errorx"
|
||||
@@ -353,7 +354,7 @@ func (d *dbSqlExecAppImpl) doExec(ctx context.Context, execSqlReq *DbSqlExecReq,
|
||||
if flowProcdefId := d.flowProcdefApp.GetProcdefIdByCodePath(ctx, dbConn.Info.CodePath...); flowProcdefId != 0 {
|
||||
bizKey := stringx.Rand(24)
|
||||
// 如果该库关联了审批流程,则启动流程实例即可
|
||||
_, err := d.flowProcinstApp.StartProc(ctx, flowProcdefId, &flowapp.StarProcParam{
|
||||
_, err := d.flowProcinstApp.StartProc(ctx, flowProcdefId, &flowdto.StarProc{
|
||||
BizType: DbSqlExecFlowBizType,
|
||||
BizKey: bizKey,
|
||||
Remark: dbSqlExecRecord.Remark,
|
||||
|
||||
23
server/internal/db/application/dto/dto.go
Normal file
23
server/internal/db/application/dto/dto.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"io"
|
||||
"mayfly-go/internal/db/domain/entity"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
)
|
||||
|
||||
type SaveDbInstance struct {
|
||||
DbInstance *entity.DbInstance
|
||||
AuthCerts []*tagentity.ResourceAuthCert
|
||||
TagCodePaths []string
|
||||
}
|
||||
|
||||
type DumpDb struct {
|
||||
DbId uint64
|
||||
DbName string
|
||||
Tables []string
|
||||
DumpDDL bool // 是否dump ddl
|
||||
DumpData bool // 是否dump data
|
||||
|
||||
Writer io.Writer
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package application
|
||||
|
||||
import "io"
|
||||
|
||||
type DumpDbReq struct {
|
||||
DbId uint64
|
||||
DbName string
|
||||
Tables []string
|
||||
DumpDDL bool // 是否dump ddl
|
||||
DumpData bool // 是否dump data
|
||||
|
||||
Writer io.Writer
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/flow/api/form"
|
||||
"mayfly-go/internal/flow/api/vo"
|
||||
"mayfly-go/internal/flow/application"
|
||||
"mayfly-go/internal/flow/application/dto"
|
||||
"mayfly-go/internal/flow/domain/entity"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
@@ -42,7 +43,7 @@ func (a *Procdef) Save(rc *req.Ctx) {
|
||||
form := &form.Procdef{}
|
||||
procdef := req.BindJsonAndCopyTo(rc, form, new(entity.Procdef))
|
||||
rc.ReqParam = form
|
||||
biz.ErrIsNil(a.ProcdefApp.SaveProcdef(rc.MetaCtx, &application.SaveProcdefParam{
|
||||
biz.ErrIsNil(a.ProcdefApp.SaveProcdef(rc.MetaCtx, &dto.SaveProcdef{
|
||||
Procdef: procdef,
|
||||
CodePaths: form.CodePaths,
|
||||
}))
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package application
|
||||
package dto
|
||||
|
||||
import "mayfly-go/internal/flow/domain/entity"
|
||||
|
||||
type SaveProcdef struct {
|
||||
Procdef *entity.Procdef
|
||||
CodePaths []string
|
||||
}
|
||||
|
||||
// 启动流程实例请求入参
|
||||
type StarProcParam struct {
|
||||
type StarProc struct {
|
||||
BizType string // 业务类型
|
||||
BizKey string // 业务key
|
||||
Remark string // 备注
|
||||
BizForm string // 业务表单信息
|
||||
}
|
||||
|
||||
type CompleteProcinstTaskParam struct {
|
||||
TaskId uint64
|
||||
Remark string // 备注
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mayfly-go/internal/flow/application/dto"
|
||||
"mayfly-go/internal/flow/domain/entity"
|
||||
"mayfly-go/internal/flow/domain/repository"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
@@ -11,18 +12,13 @@ import (
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type SaveProcdefParam struct {
|
||||
Procdef *entity.Procdef
|
||||
CodePaths []string
|
||||
}
|
||||
|
||||
type Procdef interface {
|
||||
base.App[*entity.Procdef]
|
||||
|
||||
GetPageList(condition *entity.Procdef, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
||||
|
||||
// 保存流程实例信息
|
||||
SaveProcdef(ctx context.Context, def *SaveProcdefParam) error
|
||||
SaveProcdef(ctx context.Context, def *dto.SaveProcdef) error
|
||||
|
||||
// 删除流程实例信息
|
||||
DeleteProcdef(ctx context.Context, defId uint64) error
|
||||
@@ -54,7 +50,7 @@ func (p *procdefAppImpl) GetPageList(condition *entity.Procdef, pageParam *model
|
||||
return p.Repo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *procdefAppImpl) SaveProcdef(ctx context.Context, defParam *SaveProcdefParam) error {
|
||||
func (p *procdefAppImpl) SaveProcdef(ctx context.Context, defParam *dto.SaveProcdef) error {
|
||||
def := defParam.Procdef
|
||||
if err := entity.ProcdefStatusEnum.Valid(def.Status); err != nil {
|
||||
return err
|
||||
|
||||
@@ -3,6 +3,7 @@ package application
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mayfly-go/internal/flow/application/dto"
|
||||
"mayfly-go/internal/flow/domain/entity"
|
||||
"mayfly-go/internal/flow/domain/repository"
|
||||
"mayfly-go/pkg/base"
|
||||
@@ -20,7 +21,7 @@ type Procinst interface {
|
||||
GetProcinstTasks(condition *entity.ProcinstTaskQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
||||
|
||||
// StartProc 根据流程定义启动一个流程实例
|
||||
StartProc(ctx context.Context, procdefId uint64, reqParam *StarProcParam) (*entity.Procinst, error)
|
||||
StartProc(ctx context.Context, procdefId uint64, reqParam *dto.StarProc) (*entity.Procinst, error)
|
||||
|
||||
// 取消流程
|
||||
CancelProc(ctx context.Context, procinstId uint64) error
|
||||
@@ -57,7 +58,7 @@ func (p *procinstAppImpl) GetProcinstTasks(condition *entity.ProcinstTaskQuery,
|
||||
return p.procinstTaskRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *procinstAppImpl) StartProc(ctx context.Context, procdefId uint64, reqParam *StarProcParam) (*entity.Procinst, error) {
|
||||
func (p *procinstAppImpl) StartProc(ctx context.Context, procdefId uint64, reqParam *dto.StarProc) (*entity.Procinst, error) {
|
||||
procdef, err := p.procdefApp.GetById(procdefId)
|
||||
if err != nil {
|
||||
return nil, errorx.NewBiz("流程实例[%d]不存在", procdefId)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package form
|
||||
|
||||
import "mayfly-go/internal/machine/application"
|
||||
import (
|
||||
"mayfly-go/internal/machine/application/dto"
|
||||
)
|
||||
|
||||
type MachineFileForm struct {
|
||||
Id uint64 `json:"id"`
|
||||
@@ -17,32 +19,32 @@ type MachineFileUpdateForm struct {
|
||||
}
|
||||
|
||||
type CreateFileForm struct {
|
||||
*application.MachineFileOpParam
|
||||
*dto.MachineFileOp
|
||||
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type WriteFileContentForm struct {
|
||||
*application.MachineFileOpParam
|
||||
*dto.MachineFileOp
|
||||
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
type RemoveFileForm struct {
|
||||
*application.MachineFileOpParam
|
||||
*dto.MachineFileOp
|
||||
|
||||
Paths []string `json:"paths" binding:"required"`
|
||||
}
|
||||
|
||||
type CopyFileForm struct {
|
||||
*application.MachineFileOpParam
|
||||
*dto.MachineFileOp
|
||||
|
||||
Paths []string `json:"paths" binding:"required"`
|
||||
ToPath string `json:"toPath" binding:"required"`
|
||||
}
|
||||
|
||||
type RenameForm struct {
|
||||
*application.MachineFileOpParam
|
||||
*dto.MachineFileOp
|
||||
|
||||
Newname string `json:"newname" binding:"required"`
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/application/dto"
|
||||
"mayfly-go/internal/machine/config"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/guac"
|
||||
@@ -99,7 +100,7 @@ func (m *Machine) SaveMachine(rc *req.Ctx) {
|
||||
|
||||
rc.ReqParam = machineForm
|
||||
|
||||
biz.ErrIsNil(m.MachineApp.SaveMachine(rc.MetaCtx, &application.SaveMachineParam{
|
||||
biz.ErrIsNil(m.MachineApp.SaveMachine(rc.MetaCtx, &dto.SaveMachine{
|
||||
Machine: me,
|
||||
TagCodePaths: machineForm.TagCodePaths,
|
||||
AuthCerts: machineForm.AuthCerts,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/application/dto"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
@@ -37,7 +38,7 @@ func (m *MachineCmdConf) Save(rc *req.Ctx) {
|
||||
mcj := req.BindJsonAndCopyTo[*entity.MachineCmdConf](rc, cmdForm, new(entity.MachineCmdConf))
|
||||
rc.ReqParam = cmdForm
|
||||
|
||||
err := m.MachineCmdConfApp.SaveCmdConf(rc.MetaCtx, &application.SaveMachineCmdConfParam{
|
||||
err := m.MachineCmdConfApp.SaveCmdConf(rc.MetaCtx, &dto.SaveMachineCmdConf{
|
||||
CmdConf: mcj,
|
||||
CodePaths: cmdForm.CodePaths,
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/application/dto"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
@@ -44,7 +45,7 @@ func (m *MachineCronJob) Save(rc *req.Ctx) {
|
||||
mcj := req.BindJsonAndCopyTo[*entity.MachineCronJob](rc, jobForm, new(entity.MachineCronJob))
|
||||
rc.ReqParam = jobForm
|
||||
|
||||
err := m.MachineCronJobApp.SaveMachineCronJob(rc.MetaCtx, &application.SaveMachineCronJobParam{
|
||||
err := m.MachineCronJobApp.SaveMachineCronJob(rc.MetaCtx, &dto.SaveMachineCronJob{
|
||||
CronJob: mcj,
|
||||
CodePaths: jobForm.CodePaths,
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"mayfly-go/internal/machine/api/form"
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/application"
|
||||
"mayfly-go/internal/machine/application/dto"
|
||||
"mayfly-go/internal/machine/config"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/mcm"
|
||||
@@ -71,10 +72,10 @@ func (m *MachineFile) CreateFile(rc *req.Ctx) {
|
||||
var err error
|
||||
if opForm.Type == dir {
|
||||
attrs["type"] = "目录"
|
||||
mi, err = m.MachineFileApp.MkDir(rc.MetaCtx, opForm.MachineFileOpParam)
|
||||
mi, err = m.MachineFileApp.MkDir(rc.MetaCtx, opForm.MachineFileOp)
|
||||
} else {
|
||||
attrs["type"] = "文件"
|
||||
mi, err = m.MachineFileApp.CreateFile(rc.MetaCtx, opForm.MachineFileOpParam)
|
||||
mi, err = m.MachineFileApp.CreateFile(rc.MetaCtx, opForm.MachineFileOp)
|
||||
}
|
||||
attrs["machine"] = mi
|
||||
rc.ReqParam = attrs
|
||||
@@ -82,7 +83,7 @@ func (m *MachineFile) CreateFile(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (m *MachineFile) ReadFileContent(rc *req.Ctx) {
|
||||
opForm := req.BindQuery(rc, new(application.MachineFileOpParam))
|
||||
opForm := req.BindQuery(rc, new(dto.MachineFileOp))
|
||||
readPath := opForm.Path
|
||||
// 特殊处理rdp文件
|
||||
if opForm.Protocol == entity.MachineProtocolRdp {
|
||||
@@ -112,7 +113,7 @@ func (m *MachineFile) ReadFileContent(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (m *MachineFile) DownloadFile(rc *req.Ctx) {
|
||||
opForm := req.BindQuery(rc, new(application.MachineFileOpParam))
|
||||
opForm := req.BindQuery(rc, new(dto.MachineFileOp))
|
||||
|
||||
readPath := opForm.Path
|
||||
|
||||
@@ -140,7 +141,7 @@ func (m *MachineFile) DownloadFile(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (m *MachineFile) GetDirEntry(rc *req.Ctx) {
|
||||
opForm := req.BindQuery(rc, new(application.MachineFileOpParam))
|
||||
opForm := req.BindQuery(rc, new(dto.MachineFileOp))
|
||||
readPath := opForm.Path
|
||||
rc.ReqParam = fmt.Sprintf("path: %s", readPath)
|
||||
|
||||
@@ -173,7 +174,7 @@ func (m *MachineFile) GetDirEntry(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (m *MachineFile) GetDirSize(rc *req.Ctx) {
|
||||
opForm := req.BindQuery(rc, new(application.MachineFileOpParam))
|
||||
opForm := req.BindQuery(rc, new(dto.MachineFileOp))
|
||||
|
||||
size, err := m.MachineFileApp.GetDirSize(rc.MetaCtx, opForm)
|
||||
biz.ErrIsNil(err)
|
||||
@@ -181,7 +182,7 @@ func (m *MachineFile) GetDirSize(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (m *MachineFile) GetFileStat(rc *req.Ctx) {
|
||||
opForm := req.BindQuery(rc, new(application.MachineFileOpParam))
|
||||
opForm := req.BindQuery(rc, new(dto.MachineFileOp))
|
||||
res, err := m.MachineFileApp.FileStat(rc.MetaCtx, opForm)
|
||||
biz.ErrIsNil(err, res)
|
||||
rc.ResData = res
|
||||
@@ -191,7 +192,7 @@ func (m *MachineFile) WriteFileContent(rc *req.Ctx) {
|
||||
opForm := req.BindJsonAndValid(rc, new(form.WriteFileContentForm))
|
||||
path := opForm.Path
|
||||
|
||||
mi, err := m.MachineFileApp.WriteFileContent(rc.MetaCtx, opForm.MachineFileOpParam, []byte(opForm.Content))
|
||||
mi, err := m.MachineFileApp.WriteFileContent(rc.MetaCtx, opForm.MachineFileOp, []byte(opForm.Content))
|
||||
rc.ReqParam = collx.Kvs("machine", mi, "path", path)
|
||||
biz.ErrIsNilAppendErr(err, "打开文件失败: %s")
|
||||
}
|
||||
@@ -219,7 +220,7 @@ func (m *MachineFile) UploadFile(rc *req.Ctx) {
|
||||
}
|
||||
}()
|
||||
|
||||
opForm := &application.MachineFileOpParam{
|
||||
opForm := &dto.MachineFileOp{
|
||||
MachineId: machineId,
|
||||
AuthCertName: authCertName,
|
||||
Protocol: protocol,
|
||||
@@ -259,7 +260,7 @@ func (m *MachineFile) UploadFolder(rc *req.Ctx) {
|
||||
// protocol
|
||||
protocol := cast.ToInt(mf.Value["protocol"][0])
|
||||
|
||||
opForm := &application.MachineFileOpParam{
|
||||
opForm := &dto.MachineFileOp{
|
||||
MachineId: machineId,
|
||||
Protocol: protocol,
|
||||
AuthCertName: authCertName,
|
||||
@@ -347,28 +348,28 @@ func (m *MachineFile) UploadFolder(rc *req.Ctx) {
|
||||
func (m *MachineFile) RemoveFile(rc *req.Ctx) {
|
||||
opForm := req.BindJsonAndValid(rc, new(form.RemoveFileForm))
|
||||
|
||||
mi, err := m.MachineFileApp.RemoveFile(rc.MetaCtx, opForm.MachineFileOpParam, opForm.Paths...)
|
||||
mi, err := m.MachineFileApp.RemoveFile(rc.MetaCtx, opForm.MachineFileOp, opForm.Paths...)
|
||||
rc.ReqParam = collx.Kvs("machine", mi, "path", opForm)
|
||||
biz.ErrIsNilAppendErr(err, "删除文件失败: %s")
|
||||
}
|
||||
|
||||
func (m *MachineFile) CopyFile(rc *req.Ctx) {
|
||||
opForm := req.BindJsonAndValid(rc, new(form.CopyFileForm))
|
||||
mi, err := m.MachineFileApp.Copy(rc.MetaCtx, opForm.MachineFileOpParam, opForm.ToPath, opForm.Paths...)
|
||||
mi, err := m.MachineFileApp.Copy(rc.MetaCtx, opForm.MachineFileOp, opForm.ToPath, opForm.Paths...)
|
||||
biz.ErrIsNilAppendErr(err, "文件拷贝失败: %s")
|
||||
rc.ReqParam = collx.Kvs("machine", mi, "cp", opForm)
|
||||
}
|
||||
|
||||
func (m *MachineFile) MvFile(rc *req.Ctx) {
|
||||
opForm := req.BindJsonAndValid(rc, new(form.CopyFileForm))
|
||||
mi, err := m.MachineFileApp.Mv(rc.MetaCtx, opForm.MachineFileOpParam, opForm.ToPath, opForm.Paths...)
|
||||
mi, err := m.MachineFileApp.Mv(rc.MetaCtx, opForm.MachineFileOp, opForm.ToPath, opForm.Paths...)
|
||||
rc.ReqParam = collx.Kvs("machine", mi, "mv", opForm)
|
||||
biz.ErrIsNilAppendErr(err, "文件移动失败: %s")
|
||||
}
|
||||
|
||||
func (m *MachineFile) Rename(rc *req.Ctx) {
|
||||
renameForm := req.BindJsonAndValid(rc, new(form.RenameForm))
|
||||
mi, err := m.MachineFileApp.Rename(rc.MetaCtx, renameForm.MachineFileOpParam, renameForm.Newname)
|
||||
mi, err := m.MachineFileApp.Rename(rc.MetaCtx, renameForm.MachineFileOp, renameForm.Newname)
|
||||
rc.ReqParam = collx.Kvs("machine", mi, "rename", renameForm)
|
||||
biz.ErrIsNilAppendErr(err, "文件重命名失败: %s")
|
||||
}
|
||||
|
||||
29
server/internal/machine/application/dto/dto.go
Normal file
29
server/internal/machine/application/dto/dto.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
)
|
||||
|
||||
type SaveMachine struct {
|
||||
Machine *entity.Machine
|
||||
TagCodePaths []string
|
||||
AuthCerts []*tagentity.ResourceAuthCert
|
||||
}
|
||||
|
||||
type MachineFileOp struct {
|
||||
MachineId uint64 `json:"machineId" binding:"required" form:"machineId"`
|
||||
Protocol int `json:"protocol" binding:"required" form:"protocol"`
|
||||
AuthCertName string `json:"authCertName" binding:"required" form:"authCertName"` // 授权凭证
|
||||
Path string `json:"path" form:"path"` // 文件路径
|
||||
}
|
||||
|
||||
type SaveMachineCmdConf struct {
|
||||
CmdConf *entity.MachineCmdConf
|
||||
CodePaths []string
|
||||
}
|
||||
|
||||
type SaveMachineCronJob struct {
|
||||
CronJob *entity.MachineCronJob
|
||||
CodePaths []string
|
||||
}
|
||||
@@ -4,11 +4,13 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mayfly-go/internal/event"
|
||||
"mayfly-go/internal/machine/application/dto"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/internal/machine/infrastructure/cache"
|
||||
"mayfly-go/internal/machine/mcm"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
tagdto "mayfly-go/internal/tag/application/dto"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/errorx"
|
||||
@@ -19,16 +21,10 @@ import (
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
)
|
||||
|
||||
type SaveMachineParam struct {
|
||||
Machine *entity.Machine
|
||||
TagCodePaths []string
|
||||
AuthCerts []*tagentity.ResourceAuthCert
|
||||
}
|
||||
|
||||
type Machine interface {
|
||||
base.App[*entity.Machine]
|
||||
|
||||
SaveMachine(ctx context.Context, param *SaveMachineParam) error
|
||||
SaveMachine(ctx context.Context, param *dto.SaveMachine) error
|
||||
|
||||
// 测试机器连接
|
||||
TestConn(me *entity.Machine, authCert *tagentity.ResourceAuthCert) error
|
||||
@@ -81,7 +77,7 @@ func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pagePara
|
||||
return m.GetRepo().GetMachineList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (m *machineAppImpl) SaveMachine(ctx context.Context, param *SaveMachineParam) error {
|
||||
func (m *machineAppImpl) SaveMachine(ctx context.Context, param *dto.SaveMachine) error {
|
||||
me := param.Machine
|
||||
tagCodePaths := param.TagCodePaths
|
||||
authCerts := param.AuthCerts
|
||||
@@ -119,7 +115,7 @@ func (m *machineAppImpl) SaveMachine(ctx context.Context, param *SaveMachinePara
|
||||
})
|
||||
|
||||
}, func(ctx context.Context) error {
|
||||
return m.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
return m.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: m.genMachineResourceTag(me, authCerts),
|
||||
ParentTagCodePaths: tagCodePaths,
|
||||
})
|
||||
@@ -153,7 +149,7 @@ func (m *machineAppImpl) SaveMachine(ctx context.Context, param *SaveMachinePara
|
||||
return err
|
||||
}
|
||||
}
|
||||
return m.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
return m.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: m.genMachineResourceTag(oldMachine, authCerts),
|
||||
ParentTagCodePaths: tagCodePaths,
|
||||
})
|
||||
@@ -216,8 +212,8 @@ func (m *machineAppImpl) Delete(ctx context.Context, id uint64) error {
|
||||
func(ctx context.Context) error {
|
||||
return m.DeleteById(ctx, id)
|
||||
}, func(ctx context.Context) error {
|
||||
return m.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
ResourceTag: &tagapp.ResourceTag{
|
||||
return m.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: &tagdto.ResourceTag{
|
||||
Code: machine.Code,
|
||||
Type: tagentity.TagTypeMachine,
|
||||
},
|
||||
@@ -362,16 +358,16 @@ func (m *machineAppImpl) toMi(me *entity.Machine, authCert *tagentity.ResourceAu
|
||||
return mi, nil
|
||||
}
|
||||
|
||||
func (m *machineAppImpl) genMachineResourceTag(me *entity.Machine, authCerts []*tagentity.ResourceAuthCert) *tagapp.ResourceTag {
|
||||
authCertTags := collx.ArrayMap[*tagentity.ResourceAuthCert, *tagapp.ResourceTag](authCerts, func(val *tagentity.ResourceAuthCert) *tagapp.ResourceTag {
|
||||
return &tagapp.ResourceTag{
|
||||
func (m *machineAppImpl) genMachineResourceTag(me *entity.Machine, authCerts []*tagentity.ResourceAuthCert) *tagdto.ResourceTag {
|
||||
authCertTags := collx.ArrayMap[*tagentity.ResourceAuthCert, *tagdto.ResourceTag](authCerts, func(val *tagentity.ResourceAuthCert) *tagdto.ResourceTag {
|
||||
return &tagdto.ResourceTag{
|
||||
Code: val.Name,
|
||||
Name: val.Username,
|
||||
Type: tagentity.TagTypeMachineAuthCert,
|
||||
}
|
||||
})
|
||||
|
||||
return &tagapp.ResourceTag{
|
||||
return &tagdto.ResourceTag{
|
||||
Code: me.Code,
|
||||
Type: tagentity.TagTypeMachine,
|
||||
Name: me.Name,
|
||||
|
||||
@@ -2,6 +2,7 @@ package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mayfly-go/internal/machine/application/dto"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
@@ -12,11 +13,6 @@ import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type SaveMachineCmdConfParam struct {
|
||||
CmdConf *entity.MachineCmdConf
|
||||
CodePaths []string
|
||||
}
|
||||
|
||||
type MachineCmd struct {
|
||||
CmdRegexp *regexp.Regexp // 命令正则表达式
|
||||
Stratege string // 策略(拒绝或审批等)
|
||||
@@ -25,7 +21,7 @@ type MachineCmd struct {
|
||||
type MachineCmdConf interface {
|
||||
base.App[*entity.MachineCmdConf]
|
||||
|
||||
SaveCmdConf(ctx context.Context, cmdConf *SaveMachineCmdConfParam) error
|
||||
SaveCmdConf(ctx context.Context, cmdConf *dto.SaveMachineCmdConf) error
|
||||
|
||||
DeleteCmdConf(ctx context.Context, id uint64) error
|
||||
|
||||
@@ -45,7 +41,7 @@ func (m *machineCmdConfAppImpl) InjectMachineCmdConfRepo(repo repository.Machine
|
||||
m.Repo = repo
|
||||
}
|
||||
|
||||
func (m *machineCmdConfAppImpl) SaveCmdConf(ctx context.Context, cmdConfParam *SaveMachineCmdConfParam) error {
|
||||
func (m *machineCmdConfAppImpl) SaveCmdConf(ctx context.Context, cmdConfParam *dto.SaveMachineCmdConf) error {
|
||||
cmdConf := cmdConfParam.CmdConf
|
||||
|
||||
return m.Tx(ctx, func(ctx context.Context) error {
|
||||
|
||||
@@ -2,6 +2,7 @@ package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mayfly-go/internal/machine/application/dto"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
@@ -19,11 +20,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type SaveMachineCronJobParam struct {
|
||||
CronJob *entity.MachineCronJob
|
||||
CodePaths []string
|
||||
}
|
||||
|
||||
type MachineCronJob interface {
|
||||
base.App[*entity.MachineCronJob]
|
||||
|
||||
@@ -33,7 +29,7 @@ type MachineCronJob interface {
|
||||
// 获取分页执行结果列表
|
||||
GetExecPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
||||
|
||||
SaveMachineCronJob(ctx context.Context, param *SaveMachineCronJobParam) error
|
||||
SaveMachineCronJob(ctx context.Context, param *dto.SaveMachineCronJob) error
|
||||
|
||||
Delete(ctx context.Context, id uint64)
|
||||
|
||||
@@ -73,7 +69,7 @@ func (m *machineCronJobAppImpl) GetExecPageList(condition *entity.MachineCronJob
|
||||
}
|
||||
|
||||
// 保存机器任务信息
|
||||
func (m *machineCronJobAppImpl) SaveMachineCronJob(ctx context.Context, param *SaveMachineCronJobParam) error {
|
||||
func (m *machineCronJobAppImpl) SaveMachineCronJob(ctx context.Context, param *dto.SaveMachineCronJob) error {
|
||||
mcj := param.CronJob
|
||||
|
||||
// 赋值cron job key
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"mayfly-go/internal/machine/application/dto"
|
||||
"mayfly-go/internal/machine/config"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
@@ -25,13 +26,6 @@ import (
|
||||
"github.com/pkg/sftp"
|
||||
)
|
||||
|
||||
type MachineFileOpParam struct {
|
||||
MachineId uint64 `json:"machineId" binding:"required" form:"machineId"`
|
||||
Protocol int `json:"protocol" binding:"required" form:"protocol"`
|
||||
AuthCertName string `json:"authCertName" binding:"required" form:"authCertName"` // 授权凭证
|
||||
Path string `json:"path" form:"path"` // 文件路径
|
||||
}
|
||||
|
||||
type MachineFile interface {
|
||||
base.App[*entity.MachineFile]
|
||||
|
||||
@@ -51,39 +45,39 @@ type MachineFile interface {
|
||||
/** sftp 相关操作 **/
|
||||
|
||||
// 创建目录
|
||||
MkDir(ctx context.Context, opParam *MachineFileOpParam) (*mcm.MachineInfo, error)
|
||||
MkDir(ctx context.Context, opParam *dto.MachineFileOp) (*mcm.MachineInfo, error)
|
||||
|
||||
// 创建文件
|
||||
CreateFile(ctx context.Context, opParam *MachineFileOpParam) (*mcm.MachineInfo, error)
|
||||
CreateFile(ctx context.Context, opParam *dto.MachineFileOp) (*mcm.MachineInfo, error)
|
||||
|
||||
// 读取目录
|
||||
ReadDir(ctx context.Context, opParam *MachineFileOpParam) ([]fs.FileInfo, error)
|
||||
ReadDir(ctx context.Context, opParam *dto.MachineFileOp) ([]fs.FileInfo, error)
|
||||
|
||||
// 获取指定目录内容大小
|
||||
GetDirSize(ctx context.Context, opParam *MachineFileOpParam) (string, error)
|
||||
GetDirSize(ctx context.Context, opParam *dto.MachineFileOp) (string, error)
|
||||
|
||||
// 获取文件stat
|
||||
FileStat(ctx context.Context, opParam *MachineFileOpParam) (string, error)
|
||||
FileStat(ctx context.Context, opParam *dto.MachineFileOp) (string, error)
|
||||
|
||||
// 读取文件内容
|
||||
ReadFile(ctx context.Context, opParam *MachineFileOpParam) (*sftp.File, *mcm.MachineInfo, error)
|
||||
ReadFile(ctx context.Context, opParam *dto.MachineFileOp) (*sftp.File, *mcm.MachineInfo, error)
|
||||
|
||||
// 写文件
|
||||
WriteFileContent(ctx context.Context, opParam *MachineFileOpParam, content []byte) (*mcm.MachineInfo, error)
|
||||
WriteFileContent(ctx context.Context, opParam *dto.MachineFileOp, content []byte) (*mcm.MachineInfo, error)
|
||||
|
||||
// 文件上传
|
||||
UploadFile(ctx context.Context, opParam *MachineFileOpParam, filename string, reader io.Reader) (*mcm.MachineInfo, error)
|
||||
UploadFile(ctx context.Context, opParam *dto.MachineFileOp, filename string, reader io.Reader) (*mcm.MachineInfo, error)
|
||||
|
||||
UploadFiles(ctx context.Context, opParam *MachineFileOpParam, basePath string, fileHeaders []*multipart.FileHeader, paths []string) (*mcm.MachineInfo, error)
|
||||
UploadFiles(ctx context.Context, opParam *dto.MachineFileOp, basePath string, fileHeaders []*multipart.FileHeader, paths []string) (*mcm.MachineInfo, error)
|
||||
|
||||
// 移除文件
|
||||
RemoveFile(ctx context.Context, opParam *MachineFileOpParam, path ...string) (*mcm.MachineInfo, error)
|
||||
RemoveFile(ctx context.Context, opParam *dto.MachineFileOp, path ...string) (*mcm.MachineInfo, error)
|
||||
|
||||
Copy(ctx context.Context, opParam *MachineFileOpParam, toPath string, path ...string) (*mcm.MachineInfo, error)
|
||||
Copy(ctx context.Context, opParam *dto.MachineFileOp, toPath string, path ...string) (*mcm.MachineInfo, error)
|
||||
|
||||
Mv(ctx context.Context, opParam *MachineFileOpParam, toPath string, path ...string) (*mcm.MachineInfo, error)
|
||||
Mv(ctx context.Context, opParam *dto.MachineFileOp, toPath string, path ...string) (*mcm.MachineInfo, error)
|
||||
|
||||
Rename(ctx context.Context, opParam *MachineFileOpParam, newname string) (*mcm.MachineInfo, error)
|
||||
Rename(ctx context.Context, opParam *dto.MachineFileOp, newname string) (*mcm.MachineInfo, error)
|
||||
}
|
||||
|
||||
type machineFileAppImpl struct {
|
||||
@@ -121,7 +115,7 @@ func (m *machineFileAppImpl) Save(ctx context.Context, mf *entity.MachineFile) e
|
||||
return m.Insert(ctx, mf)
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) ReadDir(ctx context.Context, opParam *MachineFileOpParam) ([]fs.FileInfo, error) {
|
||||
func (m *machineFileAppImpl) ReadDir(ctx context.Context, opParam *dto.MachineFileOp) ([]fs.FileInfo, error) {
|
||||
path := opParam.Path
|
||||
if !strings.HasSuffix(path, "/") {
|
||||
path = path + "/"
|
||||
@@ -147,7 +141,7 @@ func (m *machineFileAppImpl) ReadDir(ctx context.Context, opParam *MachineFileOp
|
||||
return sftpCli.ReadDir(path)
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) GetDirSize(ctx context.Context, opParam *MachineFileOpParam) (string, error) {
|
||||
func (m *machineFileAppImpl) GetDirSize(ctx context.Context, opParam *dto.MachineFileOp) (string, error) {
|
||||
path := opParam.Path
|
||||
|
||||
if opParam.Protocol == entity.MachineProtocolRdp {
|
||||
@@ -196,7 +190,7 @@ func (m *machineFileAppImpl) GetDirSize(ctx context.Context, opParam *MachineFil
|
||||
return strings.Split(res, "\t")[0], nil
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) FileStat(ctx context.Context, opParam *MachineFileOpParam) (string, error) {
|
||||
func (m *machineFileAppImpl) FileStat(ctx context.Context, opParam *dto.MachineFileOp) (string, error) {
|
||||
path := opParam.Path
|
||||
if opParam.Protocol == entity.MachineProtocolRdp {
|
||||
path = m.GetRdpFilePath(contextx.GetLoginAccount(ctx), path)
|
||||
@@ -211,7 +205,7 @@ func (m *machineFileAppImpl) FileStat(ctx context.Context, opParam *MachineFileO
|
||||
return mcli.Run(fmt.Sprintf("stat -L %s", path))
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) MkDir(ctx context.Context, opParam *MachineFileOpParam) (*mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) MkDir(ctx context.Context, opParam *dto.MachineFileOp) (*mcm.MachineInfo, error) {
|
||||
path := opParam.Path
|
||||
if !strings.HasSuffix(path, "/") {
|
||||
path = path + "/"
|
||||
@@ -232,7 +226,7 @@ func (m *machineFileAppImpl) MkDir(ctx context.Context, opParam *MachineFileOpPa
|
||||
return mi, err
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) CreateFile(ctx context.Context, opParam *MachineFileOpParam) (*mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) CreateFile(ctx context.Context, opParam *dto.MachineFileOp) (*mcm.MachineInfo, error) {
|
||||
path := opParam.Path
|
||||
if opParam.Protocol == entity.MachineProtocolRdp {
|
||||
path = m.GetRdpFilePath(contextx.GetLoginAccount(ctx), path)
|
||||
@@ -256,7 +250,7 @@ func (m *machineFileAppImpl) CreateFile(ctx context.Context, opParam *MachineFil
|
||||
return mi, err
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) ReadFile(ctx context.Context, opParam *MachineFileOpParam) (*sftp.File, *mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) ReadFile(ctx context.Context, opParam *dto.MachineFileOp) (*sftp.File, *mcm.MachineInfo, error) {
|
||||
mi, sftpCli, err := m.GetMachineSftpCli(opParam)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -268,7 +262,7 @@ func (m *machineFileAppImpl) ReadFile(ctx context.Context, opParam *MachineFileO
|
||||
}
|
||||
|
||||
// 写文件内容
|
||||
func (m *machineFileAppImpl) WriteFileContent(ctx context.Context, opParam *MachineFileOpParam, content []byte) (*mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) WriteFileContent(ctx context.Context, opParam *dto.MachineFileOp, content []byte) (*mcm.MachineInfo, error) {
|
||||
path := opParam.Path
|
||||
if opParam.Protocol == entity.MachineProtocolRdp {
|
||||
path = m.GetRdpFilePath(contextx.GetLoginAccount(ctx), path)
|
||||
@@ -296,7 +290,7 @@ func (m *machineFileAppImpl) WriteFileContent(ctx context.Context, opParam *Mach
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
func (m *machineFileAppImpl) UploadFile(ctx context.Context, opParam *MachineFileOpParam, filename string, reader io.Reader) (*mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) UploadFile(ctx context.Context, opParam *dto.MachineFileOp, filename string, reader io.Reader) (*mcm.MachineInfo, error) {
|
||||
path := opParam.Path
|
||||
if !strings.HasSuffix(path, "/") {
|
||||
path = path + "/"
|
||||
@@ -327,7 +321,7 @@ func (m *machineFileAppImpl) UploadFile(ctx context.Context, opParam *MachineFil
|
||||
return mi, err
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) UploadFiles(ctx context.Context, opParam *MachineFileOpParam, basePath string, fileHeaders []*multipart.FileHeader, paths []string) (*mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) UploadFiles(ctx context.Context, opParam *dto.MachineFileOp, basePath string, fileHeaders []*multipart.FileHeader, paths []string) (*mcm.MachineInfo, error) {
|
||||
if opParam.Protocol == entity.MachineProtocolRdp {
|
||||
baseFolder := m.GetRdpFilePath(contextx.GetLoginAccount(ctx), basePath)
|
||||
|
||||
@@ -344,7 +338,7 @@ func (m *machineFileAppImpl) UploadFiles(ctx context.Context, opParam *MachineFi
|
||||
rdpBaseDir = rdpBaseDir + "/"
|
||||
}
|
||||
rdpDir := filepath.Dir(rdpBaseDir + paths[i])
|
||||
m.MkDir(ctx, &MachineFileOpParam{
|
||||
m.MkDir(ctx, &dto.MachineFileOp{
|
||||
MachineId: opParam.MachineId,
|
||||
Protocol: opParam.Protocol,
|
||||
Path: rdpDir,
|
||||
@@ -370,7 +364,7 @@ func (m *machineFileAppImpl) UploadFiles(ctx context.Context, opParam *MachineFi
|
||||
}
|
||||
|
||||
// 删除文件
|
||||
func (m *machineFileAppImpl) RemoveFile(ctx context.Context, opParam *MachineFileOpParam, path ...string) (*mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) RemoveFile(ctx context.Context, opParam *dto.MachineFileOp, path ...string) (*mcm.MachineInfo, error) {
|
||||
if opParam.Protocol == entity.MachineProtocolRdp {
|
||||
for _, pt := range path {
|
||||
pt = m.GetRdpFilePath(contextx.GetLoginAccount(ctx), pt)
|
||||
@@ -406,7 +400,7 @@ func (m *machineFileAppImpl) RemoveFile(ctx context.Context, opParam *MachineFil
|
||||
return minfo, err
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) Copy(ctx context.Context, opParam *MachineFileOpParam, toPath string, path ...string) (*mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) Copy(ctx context.Context, opParam *dto.MachineFileOp, toPath string, path ...string) (*mcm.MachineInfo, error) {
|
||||
if opParam.Protocol == entity.MachineProtocolRdp {
|
||||
for _, pt := range path {
|
||||
srcPath := m.GetRdpFilePath(contextx.GetLoginAccount(ctx), pt)
|
||||
@@ -442,7 +436,7 @@ func (m *machineFileAppImpl) Copy(ctx context.Context, opParam *MachineFileOpPar
|
||||
return mi, err
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) Mv(ctx context.Context, opParam *MachineFileOpParam, toPath string, path ...string) (*mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) Mv(ctx context.Context, opParam *dto.MachineFileOp, toPath string, path ...string) (*mcm.MachineInfo, error) {
|
||||
if opParam.Protocol == entity.MachineProtocolRdp {
|
||||
for _, pt := range path {
|
||||
// 获取文件名
|
||||
@@ -471,7 +465,7 @@ func (m *machineFileAppImpl) Mv(ctx context.Context, opParam *MachineFileOpParam
|
||||
return mi, err
|
||||
}
|
||||
|
||||
func (m *machineFileAppImpl) Rename(ctx context.Context, opParam *MachineFileOpParam, newname string) (*mcm.MachineInfo, error) {
|
||||
func (m *machineFileAppImpl) Rename(ctx context.Context, opParam *dto.MachineFileOp, newname string) (*mcm.MachineInfo, error) {
|
||||
oldname := opParam.Path
|
||||
if opParam.Protocol == entity.MachineProtocolRdp {
|
||||
oldname = m.GetRdpFilePath(contextx.GetLoginAccount(ctx), oldname)
|
||||
@@ -492,7 +486,7 @@ func (m *machineFileAppImpl) GetMachineCli(authCertName string) (*mcm.Cli, error
|
||||
}
|
||||
|
||||
// 获取文件机器 sftp cli
|
||||
func (m *machineFileAppImpl) GetMachineSftpCli(opParam *MachineFileOpParam) (*mcm.MachineInfo, *sftp.Client, error) {
|
||||
func (m *machineFileAppImpl) GetMachineSftpCli(opParam *dto.MachineFileOp) (*mcm.MachineInfo, *sftp.Client, error) {
|
||||
mcli, err := m.GetMachineCli(opParam.AuthCertName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"mayfly-go/internal/mongo/domain/repository"
|
||||
"mayfly-go/internal/mongo/mgm"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
tagdto "mayfly-go/internal/tag/application/dto"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/errorx"
|
||||
@@ -59,7 +60,7 @@ func (d *mongoAppImpl) Delete(ctx context.Context, id uint64) error {
|
||||
return d.DeleteById(ctx, id)
|
||||
},
|
||||
func(ctx context.Context) error {
|
||||
return d.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{ResourceTag: &tagapp.ResourceTag{
|
||||
return d.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{ResourceTag: &tagdto.ResourceTag{
|
||||
Type: tagentity.TagTypeMongo,
|
||||
Code: mongoEntity.Code,
|
||||
}})
|
||||
@@ -90,8 +91,8 @@ func (d *mongoAppImpl) SaveMongo(ctx context.Context, m *entity.Mongo, tagCodePa
|
||||
return d.Tx(ctx, func(ctx context.Context) error {
|
||||
return d.Insert(ctx, m)
|
||||
}, func(ctx context.Context) error {
|
||||
return d.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
ResourceTag: &tagapp.ResourceTag{
|
||||
return d.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: &tagdto.ResourceTag{
|
||||
Type: tagentity.TagTypeMongo,
|
||||
Code: m.Code,
|
||||
},
|
||||
@@ -121,8 +122,8 @@ func (d *mongoAppImpl) SaveMongo(ctx context.Context, m *entity.Mongo, tagCodePa
|
||||
}
|
||||
}
|
||||
|
||||
return d.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
ResourceTag: &tagapp.ResourceTag{
|
||||
return d.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: &tagdto.ResourceTag{
|
||||
Type: tagentity.TagTypeMongo,
|
||||
Code: oldMongo.Code,
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ package api
|
||||
import (
|
||||
"mayfly-go/internal/event"
|
||||
"mayfly-go/internal/redis/api/form"
|
||||
"mayfly-go/internal/redis/application"
|
||||
"mayfly-go/internal/redis/application/dto"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/req"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func (r *Redis) RunCmd(rc *req.Ctx) {
|
||||
var cmdReq form.RunCmdForm
|
||||
runCmdParam := req.BindJsonAndCopyTo(rc, &cmdReq, new(application.RunCmdParam))
|
||||
runCmdParam := req.BindJsonAndCopyTo(rc, &cmdReq, new(dto.RunCmd))
|
||||
biz.IsTrue(len(cmdReq.Cmd) > 0, "redis命令不能为空")
|
||||
|
||||
redisConn := r.getRedisConn(rc)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"mayfly-go/internal/redis/api/form"
|
||||
"mayfly-go/internal/redis/api/vo"
|
||||
"mayfly-go/internal/redis/application"
|
||||
"mayfly-go/internal/redis/application/dto"
|
||||
"mayfly-go/internal/redis/domain/entity"
|
||||
"mayfly-go/internal/redis/rdm"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
@@ -54,7 +55,7 @@ func (r *Redis) TestConn(rc *req.Ctx) {
|
||||
form := &form.Redis{}
|
||||
redis := req.BindJsonAndCopyTo[*entity.Redis](rc, form, new(entity.Redis))
|
||||
|
||||
biz.ErrIsNil(r.RedisApp.TestConn(&application.SaveRedisParam{
|
||||
biz.ErrIsNil(r.RedisApp.TestConn(&dto.SaveRedis{
|
||||
Redis: redis,
|
||||
AuthCert: &tagentity.ResourceAuthCert{
|
||||
Name: fmt.Sprintf("redis_%s_ac", redis.Code),
|
||||
@@ -70,7 +71,7 @@ func (r *Redis) Save(rc *req.Ctx) {
|
||||
form := &form.Redis{}
|
||||
redis := req.BindJsonAndCopyTo[*entity.Redis](rc, form, new(entity.Redis))
|
||||
|
||||
redisParam := &application.SaveRedisParam{
|
||||
redisParam := &dto.SaveRedis{
|
||||
Redis: redis,
|
||||
TagCodePaths: form.TagCodePaths,
|
||||
AuthCert: &tagentity.ResourceAuthCert{
|
||||
|
||||
19
server/internal/redis/application/dto/dto.go
Normal file
19
server/internal/redis/application/dto/dto.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/redis/domain/entity"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
)
|
||||
|
||||
type SaveRedis struct {
|
||||
Redis *entity.Redis
|
||||
AuthCert *tagentity.ResourceAuthCert
|
||||
TagCodePaths []string
|
||||
}
|
||||
|
||||
type RunCmd struct {
|
||||
Id uint64 `json:"id"`
|
||||
Db int `json:"db"`
|
||||
Cmd []any `json:"cmd"`
|
||||
Remark string
|
||||
}
|
||||
@@ -4,11 +4,14 @@ import (
|
||||
"context"
|
||||
"mayfly-go/internal/common/consts"
|
||||
flowapp "mayfly-go/internal/flow/application"
|
||||
flowdto "mayfly-go/internal/flow/application/dto"
|
||||
flowentity "mayfly-go/internal/flow/domain/entity"
|
||||
"mayfly-go/internal/redis/application/dto"
|
||||
"mayfly-go/internal/redis/domain/entity"
|
||||
"mayfly-go/internal/redis/domain/repository"
|
||||
"mayfly-go/internal/redis/rdm"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
tagdto "mayfly-go/internal/tag/application/dto"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/errorx"
|
||||
@@ -23,19 +26,6 @@ import (
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type SaveRedisParam struct {
|
||||
Redis *entity.Redis
|
||||
AuthCert *tagentity.ResourceAuthCert
|
||||
TagCodePaths []string
|
||||
}
|
||||
|
||||
type RunCmdParam struct {
|
||||
Id uint64 `json:"id"`
|
||||
Db int `json:"db"`
|
||||
Cmd []any `json:"cmd"`
|
||||
Remark string
|
||||
}
|
||||
|
||||
type Redis interface {
|
||||
base.App[*entity.Redis]
|
||||
flowapp.FlowBizHandler
|
||||
@@ -44,9 +34,9 @@ type Redis interface {
|
||||
GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
||||
|
||||
// 测试连接
|
||||
TestConn(re *SaveRedisParam) error
|
||||
TestConn(re *dto.SaveRedis) error
|
||||
|
||||
SaveRedis(ctx context.Context, param *SaveRedisParam) error
|
||||
SaveRedis(ctx context.Context, param *dto.SaveRedis) error
|
||||
|
||||
// 删除数据库信息
|
||||
Delete(ctx context.Context, id uint64) error
|
||||
@@ -57,7 +47,7 @@ type Redis interface {
|
||||
GetRedisConn(id uint64, db int) (*rdm.RedisConn, error)
|
||||
|
||||
// 执行redis命令
|
||||
RunCmd(ctx context.Context, redisConn *rdm.RedisConn, cmdParam *RunCmdParam) (any, error)
|
||||
RunCmd(ctx context.Context, redisConn *rdm.RedisConn, cmdParam *dto.RunCmd) (any, error)
|
||||
}
|
||||
|
||||
type redisAppImpl struct {
|
||||
@@ -79,7 +69,7 @@ func (r *redisAppImpl) GetPageList(condition *entity.RedisQuery, pageParam *mode
|
||||
return r.GetRepo().GetRedisList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (r *redisAppImpl) TestConn(param *SaveRedisParam) error {
|
||||
func (r *redisAppImpl) TestConn(param *dto.SaveRedis) error {
|
||||
db := 0
|
||||
re := param.Redis
|
||||
if re.Db != "" {
|
||||
@@ -108,7 +98,7 @@ func (r *redisAppImpl) TestConn(param *SaveRedisParam) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *redisAppImpl) SaveRedis(ctx context.Context, param *SaveRedisParam) error {
|
||||
func (r *redisAppImpl) SaveRedis(ctx context.Context, param *dto.SaveRedis) error {
|
||||
re := param.Redis
|
||||
tagCodePaths := param.TagCodePaths
|
||||
// 查找是否存在该库
|
||||
@@ -129,8 +119,8 @@ func (r *redisAppImpl) SaveRedis(ctx context.Context, param *SaveRedisParam) err
|
||||
return r.Tx(ctx, func(ctx context.Context) error {
|
||||
return r.Insert(ctx, re)
|
||||
}, func(ctx context.Context) error {
|
||||
return r.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
ResourceTag: &tagapp.ResourceTag{
|
||||
return r.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: &tagdto.ResourceTag{
|
||||
Type: tagentity.TagTypeRedis,
|
||||
Code: re.Code,
|
||||
Name: re.Name,
|
||||
@@ -171,8 +161,8 @@ func (r *redisAppImpl) SaveRedis(ctx context.Context, param *SaveRedisParam) err
|
||||
return err
|
||||
}
|
||||
}
|
||||
return r.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
ResourceTag: &tagapp.ResourceTag{
|
||||
return r.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: &tagdto.ResourceTag{
|
||||
Type: tagentity.TagTypeRedis,
|
||||
Code: oldRedis.Code,
|
||||
Name: re.Name,
|
||||
@@ -203,8 +193,8 @@ func (r *redisAppImpl) Delete(ctx context.Context, id uint64) error {
|
||||
return r.Tx(ctx, func(ctx context.Context) error {
|
||||
return r.DeleteById(ctx, id)
|
||||
}, func(ctx context.Context) error {
|
||||
return r.tagApp.SaveResourceTag(ctx, &tagapp.SaveResourceTagParam{
|
||||
ResourceTag: &tagapp.ResourceTag{
|
||||
return r.tagApp.SaveResourceTag(ctx, &tagdto.SaveResourceTag{
|
||||
ResourceTag: &tagdto.ResourceTag{
|
||||
Type: tagentity.TagTypeRedis,
|
||||
Code: re.Code,
|
||||
},
|
||||
@@ -233,14 +223,14 @@ func (r *redisAppImpl) GetRedisConn(id uint64, db int) (*rdm.RedisConn, error) {
|
||||
})
|
||||
}
|
||||
|
||||
func (r *redisAppImpl) RunCmd(ctx context.Context, redisConn *rdm.RedisConn, cmdParam *RunCmdParam) (any, error) {
|
||||
func (r *redisAppImpl) RunCmd(ctx context.Context, redisConn *rdm.RedisConn, cmdParam *dto.RunCmd) (any, error) {
|
||||
if redisConn == nil {
|
||||
return nil, errorx.NewBiz("redis连接不存在")
|
||||
}
|
||||
|
||||
// 开启工单流程,并且为写入命令,则开启对应审批流程
|
||||
if procdefId := r.procdefApp.GetProcdefIdByCodePath(ctx, redisConn.Info.CodePath...); procdefId != 0 && rdm.IsWriteCmd(cmdParam.Cmd[0]) {
|
||||
_, err := r.procinstApp.StartProc(ctx, procdefId, &flowapp.StarProcParam{
|
||||
_, err := r.procinstApp.StartProc(ctx, procdefId, &flowdto.StarProc{
|
||||
BizType: RedisRunWriteCmdFlowBizType,
|
||||
BizKey: stringx.Rand(24),
|
||||
BizForm: jsonx.ToStr(cmdParam),
|
||||
@@ -270,7 +260,7 @@ func (r *redisAppImpl) FlowBizHandle(ctx context.Context, bizHandleParam *flowap
|
||||
return nil
|
||||
}
|
||||
|
||||
runCmdParam, err := jsonx.To(bizHandleParam.BizForm, new(RunCmdParam))
|
||||
runCmdParam, err := jsonx.To(bizHandleParam.BizForm, new(dto.RunCmd))
|
||||
if err != nil {
|
||||
return errorx.NewBiz("业务表单信息解析失败: %s", err.Error())
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"mayfly-go/internal/tag/api/form"
|
||||
"mayfly-go/internal/tag/api/vo"
|
||||
"mayfly-go/internal/tag/application"
|
||||
"mayfly-go/internal/tag/application/dto"
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/req"
|
||||
@@ -45,8 +46,8 @@ func (p *TagTree) GetTagTree(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
// complteTags 补全标签信息,使其能构造为树结构
|
||||
func (p *TagTree) complteTags(resourceTags []*entity.TagTree) []*entity.TagTree {
|
||||
codePath2Tag := collx.ArrayToMap(resourceTags, func(tag *entity.TagTree) string {
|
||||
func (p *TagTree) complteTags(resourceTags []*dto.SimpleTagTree) []*dto.SimpleTagTree {
|
||||
codePath2Tag := collx.ArrayToMap(resourceTags, func(tag *dto.SimpleTagTree) string {
|
||||
return tag.CodePath
|
||||
})
|
||||
|
||||
@@ -68,7 +69,7 @@ func (p *TagTree) complteTags(resourceTags []*entity.TagTree) []*entity.TagTree
|
||||
return resourceTags
|
||||
}
|
||||
|
||||
var tags []*entity.TagTree
|
||||
var tags []*dto.SimpleTagTree
|
||||
p.TagTreeApp.ListByQuery(&entity.TagTreeQuery{CodePaths: notExistCodePaths}, &tags)
|
||||
// 完善需要补充的标签信息
|
||||
return append(resourceTags, tags...)
|
||||
@@ -77,8 +78,12 @@ func (p *TagTree) complteTags(resourceTags []*entity.TagTree) []*entity.TagTree
|
||||
func (p *TagTree) ListByQuery(rc *req.Ctx) {
|
||||
cond := new(entity.TagTreeQuery)
|
||||
tagPaths := rc.Query("tagPaths")
|
||||
cond.CodePaths = strings.Split(tagPaths, ",")
|
||||
var tagTrees vo.TagTreeVOS
|
||||
if tagPaths != "" {
|
||||
cond.CodePaths = strings.Split(tagPaths, ",")
|
||||
}
|
||||
cond.Id = uint64(rc.QueryInt("id"))
|
||||
|
||||
var tagTrees []entity.TagTree
|
||||
p.TagTreeApp.ListByQuery(cond, &tagTrees)
|
||||
rc.ResData = tagTrees
|
||||
}
|
||||
@@ -109,8 +114,8 @@ func (p *TagTree) TagResources(rc *req.Ctx) {
|
||||
accountId := rc.GetLoginAccount().Id
|
||||
tagResources := p.TagTreeApp.GetAccountTags(accountId, &entity.TagTreeQuery{Type: entity.TagType(resourceType)})
|
||||
|
||||
tagPath2Resource := collx.ArrayToMap[*entity.TagTree, string](tagResources, func(tagResource *entity.TagTree) string {
|
||||
return tagResource.GetTagPath()
|
||||
tagPath2Resource := collx.ArrayToMap[*dto.SimpleTagTree, string](tagResources, func(tagResource *dto.SimpleTagTree) string {
|
||||
return entity.GetTagPath(tagResource.CodePath)
|
||||
})
|
||||
|
||||
tagPaths := collx.MapKeys(tagPath2Resource)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"mayfly-go/internal/tag/api/form"
|
||||
"mayfly-go/internal/tag/api/vo"
|
||||
"mayfly-go/internal/tag/application"
|
||||
"mayfly-go/internal/tag/application/dto"
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/model"
|
||||
@@ -38,7 +39,7 @@ func (p *Team) GetTeams(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (p *Team) SaveTeam(rc *req.Ctx) {
|
||||
team := req.BindJsonAndValid(rc, new(application.SaveTeamParam))
|
||||
team := req.BindJsonAndValid(rc, new(dto.SaveTeam))
|
||||
rc.ReqParam = team
|
||||
biz.ErrIsNil(p.TeamApp.SaveTeam(rc.MetaCtx, team))
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package vo
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/internal/tag/application/dto"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
)
|
||||
|
||||
type TagTreeVOS []*entity.TagTree
|
||||
type TagTreeVOS []*dto.SimpleTagTree
|
||||
|
||||
type TagTreeItem struct {
|
||||
*entity.TagTree
|
||||
*dto.SimpleTagTree
|
||||
Children []*TagTreeItem `json:"children"`
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func (m *TagTreeVOS) ToTrees(pid uint64) []*TagTreeItem {
|
||||
return ttis
|
||||
}
|
||||
|
||||
ttis = collx.ArrayMap(*m, func(tr *entity.TagTree) *TagTreeItem { return &TagTreeItem{TagTree: tr} })
|
||||
ttis = collx.ArrayMap(*m, func(tr *dto.SimpleTagTree) *TagTreeItem { return &TagTreeItem{SimpleTagTree: tr} })
|
||||
tagMap := collx.ArrayToMap(ttis, func(item *TagTreeItem) string {
|
||||
return item.CodePath
|
||||
})
|
||||
|
||||
57
server/internal/tag/application/dto/tag_tree.go
Normal file
57
server/internal/tag/application/dto/tag_tree.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 保存资源标签参数
|
||||
type SaveResourceTag struct {
|
||||
ParentTagCodePaths []string // 关联标签,空数组则为删除该资源绑定的标签
|
||||
|
||||
ResourceTag *ResourceTag // 资源标签信息
|
||||
}
|
||||
|
||||
type ResourceTag struct {
|
||||
Code string
|
||||
Type entity.TagType
|
||||
Name string
|
||||
|
||||
Children []*ResourceTag // 子资源标签
|
||||
}
|
||||
|
||||
type RelateTagsByCodeAndType struct {
|
||||
ParentTagCode string // 父标签编号
|
||||
ParentTagType entity.TagType // 父标签类型
|
||||
|
||||
Tags []*ResourceTag // 要关联的标签数组
|
||||
}
|
||||
|
||||
type DelResourceTag struct {
|
||||
Id uint64
|
||||
ResourceCode string
|
||||
ResourceType entity.TagType
|
||||
|
||||
// 要删除的子节点类型,若存在值,则为删除资源标签下的指定类型的子标签
|
||||
ChildType entity.TagType
|
||||
}
|
||||
|
||||
type SimpleTagTree struct {
|
||||
Id uint64 `json:"id"`
|
||||
Type entity.TagType `json:"type"` // 类型: -1.普通标签; 其他值则为对应的资源类型
|
||||
Code string `json:"code"` // 标识编码, 若类型不为-1,则为对应资源编码
|
||||
CodePath string `json:"codePath"` // 标识路径,tag1/tag2/tagType1|tagCode/tagType2|yyycode/,非普通标签类型段含有标签类型
|
||||
Name string `json:"name"` // 名称
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
func (pt *SimpleTagTree) IsRoot() bool {
|
||||
// 去除路径两端可能存在的斜杠
|
||||
path := strings.Trim(pt.CodePath, "/")
|
||||
return len(strings.Split(path, "/")) == 1
|
||||
}
|
||||
|
||||
// GetParentPath 获取父标签路径, 如CodePath = test/test1/test2/ -> index = 0 => test/test1/ index = 1 => test/
|
||||
func (pt *SimpleTagTree) GetParentPath(index int) string {
|
||||
return entity.GetParentPath(pt.CodePath, index)
|
||||
}
|
||||
9
server/internal/tag/application/dto/team.go
Normal file
9
server/internal/tag/application/dto/team.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package dto
|
||||
|
||||
type SaveTeam struct {
|
||||
Id uint64 `json:"id"`
|
||||
Name string `json:"name" binding:"required"` // 名称
|
||||
Remark string `json:"remark"` // 备注说明
|
||||
|
||||
CodePaths []string `json:"codePaths"` // 关联标签信息
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mayfly-go/internal/tag/application/dto"
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/internal/tag/domain/repository"
|
||||
"mayfly-go/pkg/base"
|
||||
@@ -204,7 +205,7 @@ func (r *resourceAuthCertAppImpl) DeleteAuthCert(ctx context.Context, id uint64)
|
||||
return r.Tx(ctx,
|
||||
func(ctx context.Context) error {
|
||||
// 删除对应授权凭证标签
|
||||
return r.tagTreeApp.DeleteTagByParam(ctx, &DelResourceTagParam{
|
||||
return r.tagTreeApp.DeleteTagByParam(ctx, &dto.DelResourceTag{
|
||||
ResourceCode: rac.Name,
|
||||
})
|
||||
},
|
||||
@@ -332,8 +333,8 @@ func (r *resourceAuthCertAppImpl) addAuthCert(ctx context.Context, rac *entity.R
|
||||
// 若存在需要关联到的资源标签,则关联到对应的资源标签下
|
||||
if len(resourceTagCodePaths) > 0 {
|
||||
logx.DebugfContext(ctx, "[%d-%s]-授权凭证标签[%d-%s]关联至所属资源标签下[%v]", resourceType, resourceCode, authCertTagType, rac.Name, resourceTagCodePaths)
|
||||
return r.tagTreeApp.SaveResourceTag(ctx, &SaveResourceTagParam{
|
||||
ResourceTag: &ResourceTag{
|
||||
return r.tagTreeApp.SaveResourceTag(ctx, &dto.SaveResourceTag{
|
||||
ResourceTag: &dto.ResourceTag{
|
||||
Code: rac.Name,
|
||||
Type: GetResourceAuthCertTagType(entity.TagType(resourceType)),
|
||||
Name: rac.Username,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mayfly-go/internal/common/consts"
|
||||
"mayfly-go/internal/tag/application/dto"
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/internal/tag/domain/repository"
|
||||
"mayfly-go/internal/tag/infrastructure/cache"
|
||||
@@ -16,37 +17,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 保存资源标签参数
|
||||
type SaveResourceTagParam struct {
|
||||
ParentTagCodePaths []string // 关联标签,空数组则为删除该资源绑定的标签
|
||||
|
||||
ResourceTag *ResourceTag // 资源标签信息
|
||||
}
|
||||
|
||||
type ResourceTag struct {
|
||||
Code string
|
||||
Type entity.TagType
|
||||
Name string
|
||||
|
||||
Children []*ResourceTag // 子资源标签
|
||||
}
|
||||
|
||||
type RelateTagsByCodeAndTypeParam struct {
|
||||
ParentTagCode string // 父标签编号
|
||||
ParentTagType entity.TagType // 父标签类型
|
||||
|
||||
Tags []*ResourceTag // 要关联的标签数组
|
||||
}
|
||||
|
||||
type DelResourceTagParam struct {
|
||||
Id uint64
|
||||
ResourceCode string
|
||||
ResourceType entity.TagType
|
||||
|
||||
// 要删除的子节点类型,若存在值,则为删除资源标签下的指定类型的子标签
|
||||
ChildType entity.TagType
|
||||
}
|
||||
|
||||
type TagTree interface {
|
||||
base.App[*entity.TagTree]
|
||||
|
||||
@@ -55,10 +25,10 @@ type TagTree interface {
|
||||
SaveTag(ctx context.Context, pid uint64, tt *entity.TagTree) error
|
||||
|
||||
// SaveResourceTag 保存资源类型标签
|
||||
SaveResourceTag(ctx context.Context, param *SaveResourceTagParam) error
|
||||
SaveResourceTag(ctx context.Context, param *dto.SaveResourceTag) error
|
||||
|
||||
// RelateTagsByCodeAndType 将指定标签数组关联至满足指定标签类型和标签code的标签下
|
||||
RelateTagsByCodeAndType(ctx context.Context, param *RelateTagsByCodeAndTypeParam) error
|
||||
RelateTagsByCodeAndType(ctx context.Context, param *dto.RelateTagsByCodeAndType) error
|
||||
|
||||
// UpdateTagName 根据标签类型与code更新对应标签名
|
||||
UpdateTagName(ctx context.Context, tagType entity.TagType, tagCode string, tagName string) error
|
||||
@@ -70,14 +40,14 @@ type TagTree interface {
|
||||
MovingTag(ctx context.Context, fromTagPath string, toTagPath string) error
|
||||
|
||||
// DeleteTagByParam 删除标签,会删除该标签下所有子标签信息以及团队关联的标签信息
|
||||
DeleteTagByParam(ctx context.Context, param *DelResourceTagParam) error
|
||||
DeleteTagByParam(ctx context.Context, param *dto.DelResourceTag) error
|
||||
|
||||
Delete(ctx context.Context, id uint64) error
|
||||
|
||||
// GetAccountTags 获取指定账号有权限操作的标签列表
|
||||
// @param accountId 账号id
|
||||
// @param query 查询条件
|
||||
GetAccountTags(accountId uint64, query *entity.TagTreeQuery) []*entity.TagTree
|
||||
GetAccountTags(accountId uint64, query *entity.TagTreeQuery) []*dto.SimpleTagTree
|
||||
|
||||
// GetAccountTagCodes 获取指定账号有权限操作的标签codes
|
||||
GetAccountTagCodes(accountId uint64, resourceType int8, tagPath string) []string
|
||||
@@ -156,7 +126,7 @@ func (p *tagTreeAppImpl) SaveTag(ctx context.Context, pid uint64, tag *entity.Ta
|
||||
return p.UpdateById(ctx, tag)
|
||||
}
|
||||
|
||||
func (p *tagTreeAppImpl) SaveResourceTag(ctx context.Context, param *SaveResourceTagParam) error {
|
||||
func (p *tagTreeAppImpl) SaveResourceTag(ctx context.Context, param *dto.SaveResourceTag) error {
|
||||
code := param.ResourceTag.Code
|
||||
tagType := param.ResourceTag.Type
|
||||
parentTagCodePaths := param.ParentTagCodePaths
|
||||
@@ -170,7 +140,7 @@ func (p *tagTreeAppImpl) SaveResourceTag(ctx context.Context, param *SaveResourc
|
||||
|
||||
// 如果tagIds为空数组,则为删除该资源标签
|
||||
if len(parentTagCodePaths) == 0 {
|
||||
return p.DeleteTagByParam(ctx, &DelResourceTagParam{
|
||||
return p.DeleteTagByParam(ctx, &dto.DelResourceTag{
|
||||
ResourceType: tagType,
|
||||
ResourceCode: code,
|
||||
})
|
||||
@@ -233,7 +203,7 @@ func (p *tagTreeAppImpl) SaveResourceTag(ctx context.Context, param *SaveResourc
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *tagTreeAppImpl) RelateTagsByCodeAndType(ctx context.Context, param *RelateTagsByCodeAndTypeParam) error {
|
||||
func (p *tagTreeAppImpl) RelateTagsByCodeAndType(ctx context.Context, param *dto.RelateTagsByCodeAndType) error {
|
||||
parentTagCode := param.ParentTagCode
|
||||
parentTagType := param.ParentTagType
|
||||
|
||||
@@ -249,7 +219,7 @@ func (p *tagTreeAppImpl) RelateTagsByCodeAndType(ctx context.Context, param *Rel
|
||||
}
|
||||
|
||||
for _, tag := range param.Tags {
|
||||
if err := (p.SaveResourceTag(ctx, &SaveResourceTagParam{
|
||||
if err := (p.SaveResourceTag(ctx, &dto.SaveResourceTag{
|
||||
ResourceTag: tag,
|
||||
ParentTagCodePaths: parentTagCodePaths,
|
||||
})); err != nil {
|
||||
@@ -330,7 +300,7 @@ func (p *tagTreeAppImpl) MovingTag(ctx context.Context, fromTagPath string, toTa
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *tagTreeAppImpl) DeleteTagByParam(ctx context.Context, param *DelResourceTagParam) error {
|
||||
func (p *tagTreeAppImpl) DeleteTagByParam(ctx context.Context, param *dto.DelResourceTag) error {
|
||||
// 获取资源编号对应的资源标签信息
|
||||
cond := &entity.TagTree{Type: param.ResourceType, Code: param.ResourceCode}
|
||||
cond.Id = param.Id
|
||||
@@ -363,13 +333,13 @@ func (p *tagTreeAppImpl) ListByQuery(condition *entity.TagTreeQuery, toEntity an
|
||||
p.GetRepo().SelectByCondition(condition, toEntity)
|
||||
}
|
||||
|
||||
func (p *tagTreeAppImpl) GetAccountTags(accountId uint64, query *entity.TagTreeQuery) []*entity.TagTree {
|
||||
func (p *tagTreeAppImpl) GetAccountTags(accountId uint64, query *entity.TagTreeQuery) []*dto.SimpleTagTree {
|
||||
tagResourceQuery := &entity.TagTreeQuery{
|
||||
Type: query.Type,
|
||||
Types: query.Types,
|
||||
}
|
||||
|
||||
var tagResources []*entity.TagTree
|
||||
var tagResources []*dto.SimpleTagTree
|
||||
var accountTagPaths []string
|
||||
|
||||
if accountId != consts.AdminId {
|
||||
@@ -401,7 +371,7 @@ func (p *tagTreeAppImpl) GetAccountTags(accountId uint64, query *entity.TagTreeQ
|
||||
func (p *tagTreeAppImpl) GetAccountTagCodes(accountId uint64, resourceType int8, tagPath string) []string {
|
||||
tagResources := p.GetAccountTags(accountId, &entity.TagTreeQuery{Type: entity.TagType(resourceType), CodePathLikes: []string{tagPath}})
|
||||
// resouce code去重
|
||||
code2Resource := collx.ArrayToMap[*entity.TagTree, string](tagResources, func(val *entity.TagTree) string {
|
||||
code2Resource := collx.ArrayToMap[*dto.SimpleTagTree, string](tagResources, func(val *dto.SimpleTagTree) string {
|
||||
return val.Code
|
||||
})
|
||||
|
||||
@@ -411,7 +381,7 @@ func (p *tagTreeAppImpl) GetAccountTagCodes(accountId uint64, resourceType int8,
|
||||
func (p *tagTreeAppImpl) GetAccountTagCodePaths(accountId uint64, tagType entity.TagType, tagPath string) []string {
|
||||
tagResources := p.GetAccountTags(accountId, &entity.TagTreeQuery{Type: tagType, CodePathLikes: []string{tagPath}})
|
||||
// resouce code去重
|
||||
code2Resource := collx.ArrayToMap[*entity.TagTree, string](tagResources, func(val *entity.TagTree) string {
|
||||
code2Resource := collx.ArrayToMap[*dto.SimpleTagTree, string](tagResources, func(val *dto.SimpleTagTree) string {
|
||||
return val.CodePath
|
||||
})
|
||||
|
||||
@@ -484,17 +454,17 @@ func (p *tagTreeAppImpl) Delete(ctx context.Context, id uint64) error {
|
||||
return errorx.NewBiz("您无权删除该标签")
|
||||
}
|
||||
|
||||
return p.DeleteTagByParam(ctx, &DelResourceTagParam{
|
||||
return p.DeleteTagByParam(ctx, &dto.DelResourceTag{
|
||||
Id: id,
|
||||
})
|
||||
}
|
||||
|
||||
func (p *tagTreeAppImpl) toTags(parentTags []*entity.TagTree, param *ResourceTag) []*entity.TagTree {
|
||||
func (p *tagTreeAppImpl) toTags(parentTags []*entity.TagTree, param *dto.ResourceTag) []*entity.TagTree {
|
||||
tags := make([]*entity.TagTree, 0)
|
||||
|
||||
// 递归函数,将标签及其子标签展开为一个扁平数组
|
||||
var flattenTags func(parentTag *entity.TagTree, tag *ResourceTag)
|
||||
flattenTags = func(parentTag *entity.TagTree, resourceTagParam *ResourceTag) {
|
||||
var flattenTags func(parentTag *entity.TagTree, tag *dto.ResourceTag)
|
||||
flattenTags = func(parentTag *entity.TagTree, resourceTagParam *dto.ResourceTag) {
|
||||
if resourceTagParam == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mayfly-go/internal/tag/application/dto"
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/internal/tag/domain/repository"
|
||||
"mayfly-go/internal/tag/infrastructure/cache"
|
||||
@@ -13,14 +14,6 @@ import (
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type SaveTeamParam struct {
|
||||
Id uint64 `json:"id"`
|
||||
Name string `json:"name" binding:"required"` // 名称
|
||||
Remark string `json:"remark"` // 备注说明
|
||||
|
||||
CodePaths []string `json:"codePaths"` // 关联标签信息
|
||||
}
|
||||
|
||||
type Team interface {
|
||||
base.App[*entity.Team]
|
||||
|
||||
@@ -28,7 +21,7 @@ type Team interface {
|
||||
GetPageList(condition *entity.TeamQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
||||
|
||||
// SaveTeam 保存团队信息
|
||||
SaveTeam(ctx context.Context, team *SaveTeamParam) error
|
||||
SaveTeam(ctx context.Context, team *dto.SaveTeam) error
|
||||
|
||||
Delete(ctx context.Context, id uint64) error
|
||||
|
||||
@@ -62,7 +55,7 @@ func (p *teamAppImpl) GetPageList(condition *entity.TeamQuery, pageParam *model.
|
||||
return p.GetRepo().GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *teamAppImpl) SaveTeam(ctx context.Context, saveParam *SaveTeamParam) error {
|
||||
func (p *teamAppImpl) SaveTeam(ctx context.Context, saveParam *dto.SaveTeam) error {
|
||||
team := &entity.Team{Name: saveParam.Name, Remark: saveParam.Remark}
|
||||
team.Id = saveParam.Id
|
||||
|
||||
|
||||
@@ -43,39 +43,9 @@ const (
|
||||
TagTypeDbName TagType = 22 // 数据库名
|
||||
)
|
||||
|
||||
func (pt *TagTree) IsRoot() bool {
|
||||
// 去除路径两端可能存在的斜杠
|
||||
path := strings.Trim(pt.CodePath, "/")
|
||||
return len(strings.Split(path, "/")) == 1
|
||||
}
|
||||
|
||||
// GetParentPath 获取父标签路径, 如CodePath = test/test1/test2/ -> index = 0 => test/test1/ index = 1 => test/
|
||||
func (pt *TagTree) GetParentPath(index int) string {
|
||||
return GetParentPath(pt.CodePath, index)
|
||||
}
|
||||
|
||||
// GetTagPath 获取标签段路径,不获取对应资源相关路径
|
||||
func (pt *TagTree) GetTagPath() string {
|
||||
codePath := pt.CodePath
|
||||
|
||||
// 以 资源分隔符"|" 符号对字符串进行分割
|
||||
parts := strings.Split(codePath, CodePathResourceSeparator)
|
||||
if len(parts) < 2 {
|
||||
return codePath
|
||||
}
|
||||
|
||||
// 从分割后的第一个子串中提取所需部分
|
||||
substringBeforeNumber := parts[0]
|
||||
|
||||
// 找到最后一个 "/" 的位置
|
||||
lastSlashIndex := strings.LastIndex(substringBeforeNumber, CodePathSeparator)
|
||||
|
||||
// 如果找到最后一个 "/" 符号,则截取子串
|
||||
if lastSlashIndex != -1 {
|
||||
return substringBeforeNumber[:lastSlashIndex+1]
|
||||
}
|
||||
|
||||
return codePath
|
||||
return GetTagPath(pt.CodePath)
|
||||
}
|
||||
|
||||
// 标签接口资源,如果要实现资源结构体填充标签信息,则资源结构体需要实现该接口
|
||||
@@ -110,6 +80,28 @@ func (r *ResourceTags) SetTagInfo(rt ResourceTag) {
|
||||
r.Tags = append(r.Tags, rt)
|
||||
}
|
||||
|
||||
// GetTagPath 获取标签段路径,不获取对应资源相关路径
|
||||
func GetTagPath(codePath string) string {
|
||||
// 以 资源分隔符"|" 符号对字符串进行分割
|
||||
parts := strings.Split(codePath, CodePathResourceSeparator)
|
||||
if len(parts) < 2 {
|
||||
return codePath
|
||||
}
|
||||
|
||||
// 从分割后的第一个子串中提取所需部分
|
||||
substringBeforeNumber := parts[0]
|
||||
|
||||
// 找到最后一个 "/" 的位置
|
||||
lastSlashIndex := strings.LastIndex(substringBeforeNumber, CodePathSeparator)
|
||||
|
||||
// 如果找到最后一个 "/" 符号,则截取子串
|
||||
if lastSlashIndex != -1 {
|
||||
return substringBeforeNumber[:lastSlashIndex+1]
|
||||
}
|
||||
|
||||
return codePath
|
||||
}
|
||||
|
||||
// GetCodeByPath 从codePaths中提取指定标签类型的所有tagCode并去重
|
||||
// 如:codePaths = tag1/tag2/1|xxxcode/11|yyycode/, tagType = 1 -> xxxcode, tagType = 11 -> yyycode
|
||||
func GetCodeByPath(tagType TagType, codePaths ...string) []string {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/internal/tag/domain/repository"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type tagTreeRepoImpl struct {
|
||||
@@ -15,45 +16,30 @@ func newTagTreeRepo() repository.TagTree {
|
||||
}
|
||||
|
||||
func (p *tagTreeRepoImpl) SelectByCondition(condition *entity.TagTreeQuery, toEntity any, orderBy ...string) {
|
||||
sql := "SELECT p.id, p.type, p.code, p.code_path, p.name, p.remark, p.create_time, p.creator, p.update_time, p.modifier FROM t_tag_tree p WHERE p.is_deleted = 0 "
|
||||
cond := model.NewCond().Like("name", condition.Name).
|
||||
Eq("id", condition.Id).
|
||||
In("code", condition.Codes).
|
||||
In("code_path", condition.CodePaths).
|
||||
RLike("code_path", condition.CodePathLike).
|
||||
Eq("type", condition.Type).
|
||||
In("type", condition.Types).
|
||||
OrderByAsc("type").OrderByAsc("code_path")
|
||||
|
||||
params := make([]any, 0)
|
||||
if condition.Name != "" {
|
||||
sql = sql + " AND p.name LIKE ?"
|
||||
params = append(params, "%"+condition.Name+"%")
|
||||
}
|
||||
if len(condition.Codes) > 0 {
|
||||
sql = sql + " AND p.code IN (?)"
|
||||
params = append(params, condition.Codes)
|
||||
}
|
||||
if len(condition.CodePaths) > 0 {
|
||||
sql = sql + " AND p.code_path IN (?)"
|
||||
params = append(params, condition.CodePaths)
|
||||
}
|
||||
if condition.CodePathLike != "" {
|
||||
sql = sql + " AND p.code_path LIKE ?"
|
||||
params = append(params, condition.CodePathLike+"%")
|
||||
}
|
||||
if condition.Type != 0 {
|
||||
sql = sql + " AND p.type = ?"
|
||||
params = append(params, condition.Type)
|
||||
}
|
||||
if len(condition.Types) > 0 {
|
||||
sql = sql + " AND p.type IN (?)"
|
||||
params = append(params, condition.Types)
|
||||
}
|
||||
if len(condition.CodePathLikes) > 0 {
|
||||
sql = sql + " AND ("
|
||||
codePathLikesAnd := ""
|
||||
cocePathLikesParams := make([]any, 0)
|
||||
|
||||
for i, v := range condition.CodePathLikes {
|
||||
if i == 0 {
|
||||
sql = sql + "p.code_path LIKE ?"
|
||||
codePathLikesAnd = codePathLikesAnd + "code_path LIKE ?"
|
||||
} else {
|
||||
sql = sql + " OR p.code_path LIKE ?"
|
||||
codePathLikesAnd = codePathLikesAnd + " OR code_path LIKE ?"
|
||||
}
|
||||
params = append(params, v+"%")
|
||||
cocePathLikesParams = append(cocePathLikesParams, v+"%")
|
||||
}
|
||||
sql = sql + ")"
|
||||
|
||||
cond.And(codePathLikesAnd, cocePathLikesParams...)
|
||||
}
|
||||
sql = sql + " ORDER BY p.type, p.code_path"
|
||||
p.SelectBySql(sql, toEntity, params...)
|
||||
|
||||
p.SelectByCondToAny(cond, toEntity)
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func setGdbWhere(gdb *gorm.DB, cond *model.QueryCond) *gorm.DB {
|
||||
}
|
||||
|
||||
for i, v := range cond.GetWheres() {
|
||||
gdb.Where(i, v)
|
||||
gdb.Where(i, v...)
|
||||
}
|
||||
return gdb
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ import (
|
||||
"fmt"
|
||||
"mayfly-go/pkg/consts"
|
||||
"mayfly-go/pkg/utils/anyx"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
)
|
||||
|
||||
type QueryCond struct {
|
||||
selectColumns []string // 查询的列信息
|
||||
condModel any // 条件模型
|
||||
|
||||
wheres collx.M
|
||||
wheres map[string][]any
|
||||
orderBy []string
|
||||
|
||||
dest any // 结果集指针
|
||||
@@ -121,9 +120,9 @@ func (q *QueryCond) Le(column string, val any) *QueryCond {
|
||||
}
|
||||
|
||||
// And条件
|
||||
func (q *QueryCond) And(column string, val any) *QueryCond {
|
||||
func (q *QueryCond) And(column string, val ...any) *QueryCond {
|
||||
if q.wheres == nil {
|
||||
q.wheres = collx.M{}
|
||||
q.wheres = make(map[string][]any)
|
||||
}
|
||||
q.wheres[column] = val
|
||||
return q
|
||||
@@ -137,7 +136,7 @@ func (q *QueryCond) Cond(cond, column string, val any, skipBlank bool) *QueryCon
|
||||
return q.And(fmt.Sprintf("%s %s ?", column, cond), val)
|
||||
}
|
||||
|
||||
func (q *QueryCond) GetWheres() collx.M {
|
||||
func (q *QueryCond) GetWheres() map[string][]any {
|
||||
return q.wheres
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user