Skip to content

Commit 4cf9d46

Browse files
committed
feature: 自动化导入导出对模板进行回滚
1 parent b885629 commit 4cf9d46

File tree

6 files changed

+42
-33
lines changed

6 files changed

+42
-33
lines changed

server/model/system/request/sys_auto_history.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ type SysAutoHistoryCreate struct {
2121

2222
func (r *SysAutoHistoryCreate) Create() model.SysAutoCodeHistory {
2323
entity := model.SysAutoCodeHistory{
24-
Package: r.Package,
25-
Request: r.Request,
26-
Table: r.Table,
27-
StructName: r.StructName,
28-
BusinessDB: r.BusinessDB,
29-
Description: r.Description,
30-
Injections: r.Injections,
31-
Templates: r.Templates,
32-
ApiIDs: r.ApiIDs,
33-
MenuID: r.MenuID,
24+
Package: r.Package,
25+
Request: r.Request,
26+
Table: r.Table,
27+
StructName: r.StructName,
28+
BusinessDB: r.BusinessDB,
29+
Description: r.Description,
30+
Injections: r.Injections,
31+
Templates: r.Templates,
32+
ApiIDs: r.ApiIDs,
33+
MenuID: r.MenuID,
34+
ExportTemplateID: r.ExportTemplateID,
3435
}
3536
if entity.Table == "" {
3637
entity.Table = r.StructName

server/model/system/sys_auto_code_history.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@ import (
1212
// SysAutoCodeHistory 自动迁移代码记录,用于回滚,重放使用
1313
type SysAutoCodeHistory struct {
1414
global.GVA_MODEL
15-
Table string `json:"tableName" gorm:"column:table_name;comment:表名"`
16-
Package string `json:"package" gorm:"column:package;comment:模块名/插件名"`
17-
Request string `json:"request" gorm:"type:text;column:request;comment:前端传入的结构化信息"`
18-
StructName string `json:"structName" gorm:"column:struct_name;comment:结构体名称"`
19-
BusinessDB string `json:"businessDb" gorm:"column:business_db;comment:业务库"`
20-
Description string `json:"description" gorm:"column:description;comment:Struct中文名称"`
21-
Templates map[string]string `json:"template" gorm:"serializer:json;type:text;column:templates;comment:模板信息"`
22-
Injections map[string]string `json:"injections" gorm:"serializer:json;type:text;column:Injections;comment:注入路径"`
23-
Flag int `json:"flag" gorm:"column:flag;comment:[0:创建,1:回滚]"`
24-
ApiIDs []uint `json:"apiIDs" gorm:"serializer:json;column:api_ids;comment:api表注册内容"`
25-
MenuID uint `json:"menuId" gorm:"column:menu_id;comment:菜单ID"`
26-
AutoCodePackage SysAutoCodePackage `json:"autoCodePackage" gorm:"foreignKey:ID;references:PackageID"`
27-
PackageID uint `json:"packageID" gorm:"column:package_id;comment:包ID"`
15+
Table string `json:"tableName" gorm:"column:table_name;comment:表名"`
16+
Package string `json:"package" gorm:"column:package;comment:模块名/插件名"`
17+
Request string `json:"request" gorm:"type:text;column:request;comment:前端传入的结构化信息"`
18+
StructName string `json:"structName" gorm:"column:struct_name;comment:结构体名称"`
19+
BusinessDB string `json:"businessDb" gorm:"column:business_db;comment:业务库"`
20+
Description string `json:"description" gorm:"column:description;comment:Struct中文名称"`
21+
Templates map[string]string `json:"template" gorm:"serializer:json;type:text;column:templates;comment:模板信息"`
22+
Injections map[string]string `json:"injections" gorm:"serializer:json;type:text;column:Injections;comment:注入路径"`
23+
Flag int `json:"flag" gorm:"column:flag;comment:[0:创建,1:回滚]"`
24+
ApiIDs []uint `json:"apiIDs" gorm:"serializer:json;column:api_ids;comment:api表注册内容"`
25+
MenuID uint `json:"menuId" gorm:"column:menu_id;comment:菜单ID"`
26+
ExportTemplateID uint `json:"exportTemplateID" gorm:"column:export_template_id;comment:导出模板ID"`
27+
AutoCodePackage SysAutoCodePackage `json:"autoCodePackage" gorm:"foreignKey:ID;references:PackageID"`
28+
PackageID uint `json:"packageID" gorm:"column:package_id;comment:包ID"`
2829
}
2930

3031
func (s *SysAutoCodeHistory) BeforeCreate(db *gorm.DB) error {

server/resource/package/web/view/table.vue.tpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- $global := . }}
2-
{{- $templateID := .Package + "_" + .StructName }}
2+
{{- $templateID := printf "%s_%s" .Package .StructName }}
33
<template>
44
<div>
55
<div class="gva-search-box">
@@ -153,11 +153,11 @@
153153
<div class="gva-btn-list">
154154
<el-button {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.add"{{ end }} type="primary" icon="plus" @click="openDialog">新增</el-button>
155155
<el-button {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.batchDelete"{{ end }} icon="delete" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="onDelete">删除</el-button>
156-
{{- if .HasExcel -}}
156+
{{ if .HasExcel -}}
157157
<ExportTemplate {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportTemplate"{{ end }} template-id="{{$templateID}}" />
158158
<ExportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportExcel"{{ end }} template-id="{{$templateID}}" />
159159
<ImportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.importExcel"{{ end }} template-id="{{$templateID}}" @on-success="getTableData" />
160-
{{- end -}}
160+
{{- end }}
161161
</div>
162162
<el-table
163163
ref="multipleTable"
@@ -446,14 +446,14 @@ import { ref, reactive } from 'vue'
446446
import { useBtnAuth } from '@/utils/btnAuth'
447447
{{- end }}
448448
449-
{{- if .HasExcel -}}
449+
{{if .HasExcel -}}
450450
// 导出组件
451451
import ExportExcel from '@/components/exportExcel/exportExcel.vue'
452452
// 导入组件
453453
import ImportExcel from '@/components/exportExcel/importExcel.vue'
454454
// 导出模板组件
455455
import ExportTemplate from '@/components/exportExcel/exportTemplate.vue'
456-
{{- end -}}
456+
{{- end}}
457457
458458
459459
defineOptions({

server/resource/plugin/web/view/view.vue.template

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{- $global := . }}
2+
{{- $templateID := printf "%s_%s" .Package .StructName }}
23
<template>
34
<div>
45
<div class="gva-search-box">
@@ -152,11 +153,11 @@
152153
<div class="gva-btn-list">
153154
<el-button {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.add"{{ end }} type="primary" icon="plus" @click="openDialog">新增</el-button>
154155
<el-button {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.batchDelete"{{ end }} icon="delete" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="onDelete">删除</el-button>
155-
{{- if .HasExcel -}}
156+
{{ if .HasExcel -}}
156157
<ExportTemplate {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportTemplate"{{ end }} template-id="{{$templateID}}" />
157158
<ExportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.exportExcel"{{ end }} template-id="{{$templateID}}" />
158159
<ImportExcel {{ if $global.AutoCreateBtnAuth }}v-auth="btnAuth.importExcel"{{ end }} template-id="{{$templateID}}" @on-success="getTableData" />
159-
{{- end -}}
160+
{{- end }}
160161
</div>
161162
<el-table
162163
ref="multipleTable"
@@ -450,14 +451,14 @@ import { ref, reactive } from 'vue'
450451
import { useBtnAuth } from '@/utils/btnAuth'
451452
{{- end }}
452453

453-
{{- if .HasExcel -}}
454+
{{if .HasExcel -}}
454455
// 导出组件
455456
import ExportExcel from '@/components/exportExcel/exportExcel.vue'
456457
// 导入组件
457458
import ImportExcel from '@/components/exportExcel/importExcel.vue'
458459
// 导出模板组件
459460
import ExportTemplate from '@/components/exportExcel/exportTemplate.vue'
460-
{{- end -}}
461+
{{- end}}
461462

462463

463464
defineOptions({

server/service/system/auto_code_history.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func (s *autoCodeHistory) RollBack(ctx context.Context, info request.SysAutoHist
6767
if err != nil {
6868
return err
6969
}
70+
if history.ExportTemplateID != 0 {
71+
err = global.GVA_DB.Delete(&model.SysExportTemplate{}, "id = ?", history.ExportTemplateID).Error
72+
if err != nil {
73+
return err
74+
}
75+
}
7076
if info.DeleteApi {
7177
ids := info.ApiIds(history)
7278
err = ApiServiceApp.DeleteApisByIds(ids)

server/service/system/auto_code_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (s *autoCodeTemplate) Create(ctx context.Context, info request.AutoCode) er
154154
fieldsMap[field.ColumnName] = field.FieldDesc
155155
}
156156
}
157-
templateInfo, _ := json.Marshal(info)
157+
templateInfo, _ := json.Marshal(fieldsMap)
158158
sysExportTemplate := model.SysExportTemplate{
159159
DBName: dbName,
160160
Name: name,

0 commit comments

Comments
 (0)