Skip to content

Commit 262febf

Browse files
committed
feature:增加API导入导出,方便填写录入,暂时屏蔽自动书写导入的创建时间的功能,等待gorm合并pr后恢复。
1 parent eca9c4d commit 262febf

File tree

6 files changed

+109
-24
lines changed

6 files changed

+109
-24
lines changed

server/go.mod

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ require (
3636
github.com/unrolled/secure v1.13.0
3737
github.com/xuri/excelize/v2 v2.8.0
3838
go.mongodb.org/mongo-driver v1.12.1
39+
go.uber.org/automaxprocs v1.5.3
3940
go.uber.org/zap v1.24.0
4041
golang.org/x/crypto v0.16.0
4142
golang.org/x/sync v0.5.0
4243
golang.org/x/text v0.14.0
43-
gorm.io/driver/mysql v1.5.1
44+
gorm.io/driver/mysql v1.5.6
4445
gorm.io/driver/postgres v1.5.2
4546
gorm.io/driver/sqlserver v1.5.1
46-
gorm.io/gorm v1.25.2
47+
gorm.io/gorm v1.25.7
4748
nhooyr.io/websocket v1.8.7
4849
)
4950

@@ -123,7 +124,6 @@ require (
123124
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
124125
github.com/yusufpapurcu/wmi v1.2.3 // indirect
125126
go.uber.org/atomic v1.9.0 // indirect
126-
go.uber.org/automaxprocs v1.5.3 // indirect
127127
go.uber.org/multierr v1.8.0 // indirect
128128
golang.org/x/arch v0.3.0 // indirect
129129
golang.org/x/image v0.11.0 // indirect
@@ -134,7 +134,6 @@ require (
134134
google.golang.org/protobuf v1.30.0 // indirect
135135
gopkg.in/ini.v1 v1.67.0 // indirect
136136
gopkg.in/yaml.v3 v3.0.1 // indirect
137-
gorm.io/datatypes v1.2.0 // indirect
138137
gorm.io/plugin/dbresolver v1.4.1 // indirect
139138
modernc.org/libc v1.24.1 // indirect
140139
modernc.org/mathutil v1.5.0 // indirect

server/go.sum

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
301301
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
302302
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
303303
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
304-
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
305-
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
306304
github.com/microsoft/go-mssqldb v1.1.0 h1:jsV+tpvcPTbNNKW0o3kiCD69kOHICsfjZ2VcVu2lKYc=
307305
github.com/microsoft/go-mssqldb v1.1.0/go.mod h1:LzkFdl4z2Ck+Hi+ycGOTbL56VEfgoyA2DvYejrNGbRk=
308306
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
@@ -342,6 +340,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
342340
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
343341
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
344342
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
343+
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
345344
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
346345
github.com/qiniu/api.v7/v7 v7.4.1 h1:BnNUBimLk6nrA/mIwsww9yJRupmViSsb1ndLMC7a9OY=
347346
github.com/qiniu/api.v7/v7 v7.4.1/go.mod h1:VE5oC5rkE1xul0u1S2N0b2Uxq9/6hZzhyqjgK25XDcM=
@@ -836,22 +835,18 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
836835
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
837836
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
838837
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
839-
gorm.io/datatypes v1.2.0 h1:5YT+eokWdIxhJgWHdrb2zYUimyk0+TaFth+7a0ybzco=
840-
gorm.io/datatypes v1.2.0/go.mod h1:o1dh0ZvjIjhH/bngTpypG6lVRJ5chTBxE09FH/71k04=
841838
gorm.io/driver/mysql v1.4.3/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
842-
gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
843-
gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
839+
gorm.io/driver/mysql v1.5.6 h1:Ld4mkIickM+EliaQZQx3uOJDJHtrd70MxAUqWqlx3Y8=
840+
gorm.io/driver/mysql v1.5.6/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
844841
gorm.io/driver/postgres v1.5.2 h1:ytTDxxEv+MplXOfFe3Lzm7SjG09fcdb3Z/c056DTBx0=
845842
gorm.io/driver/postgres v1.5.2/go.mod h1:fmpX0m2I1PKuR7mKZiEluwrP3hbs+ps7JIGMUBpCgl8=
846-
gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU=
847-
gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI=
848843
gorm.io/driver/sqlserver v1.5.1 h1:wpyW/pR26U94uaujltiFGXY7fd2Jw5hC9PB1ZF/Y5s4=
849844
gorm.io/driver/sqlserver v1.5.1/go.mod h1:AYHzzte2msKTmYBYsSIq8ZUsznLJwBdkB2wpI+kt0nM=
850845
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
851846
gorm.io/gorm v1.24.3/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
852847
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
853-
gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho=
854-
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
848+
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
849+
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
855850
gorm.io/plugin/dbresolver v1.4.1 h1:Ug4LcoPhrvqq71UhxtF346f+skTYoCa/nEsdjvHwEzk=
856851
gorm.io/plugin/dbresolver v1.4.1/go.mod h1:CTbCtMWhsjXSiJqiW2R8POvJ2cq18RVOl4WGyT5nhNc=
857852
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

server/service/system/sys_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (apiService *ApiService) GetAPIInfoList(api system.SysApi, info request.Pag
107107

108108
err = db.Order(OrderStr).Find(&apiList).Error
109109
} else {
110-
err = db.Order("api_group").Find(&apiList).Error
110+
err = db.Order("id desc").Find(&apiList).Error
111111
}
112112
}
113113
return apiList, total, err

server/service/system/sys_export_template.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"net/url"
1616
"strconv"
1717
"strings"
18-
"time"
1918
)
2019

2120
type SysExportTemplateService struct {
@@ -316,14 +315,17 @@ func (sysExportTemplateService *SysExportTemplateService) ImportExcel(templateID
316315
key := titleKeyMap[excelTitle[ii]]
317316
item[key] = value
318317
}
319-
needCreated := tx.Migrator().HasColumn(template.TableName, "created_at")
320-
needUpdated := tx.Migrator().HasColumn(template.TableName, "updated_at")
321-
if item["created_at"] == nil && needCreated {
322-
item["created_at"] = time.Now()
323-
}
324-
if item["updated_at"] == nil && needUpdated {
325-
item["updated_at"] = time.Now()
326-
}
318+
319+
// 此处需要等待gorm修复HasColumn中的painc问题
320+
//needCreated := tx.Migrator().HasColumn(template.TableName, "created_at")
321+
//needUpdated := tx.Migrator().HasColumn(template.TableName, "updated_at")
322+
//
323+
//if item["created_at"] == nil && needCreated {
324+
// item["created_at"] = time.Now()
325+
//}
326+
//if item["updated_at"] == nil && needUpdated {
327+
// item["updated_at"] = time.Now()
328+
//}
327329

328330
cErr := tx.Table(template.TableName).Create(&item).Error
329331
if cErr != nil {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package system
2+
3+
import (
4+
"context"
5+
sysModel "github.com/flipped-aurora/gin-vue-admin/server/model/system"
6+
"github.com/flipped-aurora/gin-vue-admin/server/service/system"
7+
"github.com/pkg/errors"
8+
"gorm.io/gorm"
9+
)
10+
11+
type initExcelTemplate struct{}
12+
13+
const initOrderExcelTemplate = initOrderDictDetail + 1
14+
15+
// auto run
16+
func init() {
17+
system.RegisterInit(initOrderExcelTemplate, &initExcelTemplate{})
18+
}
19+
20+
func (i initExcelTemplate) InitializerName() string {
21+
return "sys_export_templates"
22+
}
23+
24+
func (i *initExcelTemplate) MigrateTable(ctx context.Context) (context.Context, error) {
25+
db, ok := ctx.Value("db").(*gorm.DB)
26+
if !ok {
27+
return ctx, system.ErrMissingDBContext
28+
}
29+
return ctx, db.AutoMigrate(&sysModel.SysExportTemplate{})
30+
}
31+
32+
func (i *initExcelTemplate) TableCreated(ctx context.Context) bool {
33+
db, ok := ctx.Value("db").(*gorm.DB)
34+
if !ok {
35+
return false
36+
}
37+
return db.Migrator().HasTable(&sysModel.SysExportTemplate{})
38+
}
39+
40+
func (i *initExcelTemplate) InitializeData(ctx context.Context) (context.Context, error) {
41+
db, ok := ctx.Value("db").(*gorm.DB)
42+
if !ok {
43+
return ctx, system.ErrMissingDBContext
44+
}
45+
46+
entities := []sysModel.SysExportTemplate{
47+
{
48+
Name: "api",
49+
TableName: "sys_apis",
50+
TemplateID: "api",
51+
TemplateInfo: `{
52+
"path":"路径",
53+
"method":"方法(大写)",
54+
"description":"方法介绍",
55+
"api_group":"方法分组"
56+
}`,
57+
},
58+
}
59+
if err := db.Create(&entities).Error; err != nil {
60+
return ctx, errors.Wrap(err, "sys_export_templates"+"表数据初始化失败!")
61+
}
62+
next := context.WithValue(ctx, i.InitializerName(), entities)
63+
return next, nil
64+
}
65+
66+
func (i *initExcelTemplate) DataInserted(ctx context.Context) bool {
67+
db, ok := ctx.Value("db").(*gorm.DB)
68+
if !ok {
69+
return false
70+
}
71+
if errors.Is(db.First(&sysModel.SysExportTemplate{}).Error, gorm.ErrRecordNotFound) {
72+
return false
73+
}
74+
return true
75+
}

web/src/view/superAdmin/api/api.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@
7171
icon="Refresh"
7272
@click="onFresh"
7373
>刷新缓存</el-button>
74+
<ExportTemplate
75+
template-id="api"
76+
/>
77+
<ExportExcel
78+
template-id="api"
79+
:limit="9999"
80+
/>
81+
<ImportExcel
82+
template-id="api"
83+
@on-success="getTableData"
84+
/>
7485
</div>
7586
<el-table
7687
:data="tableData"
@@ -252,6 +263,9 @@ import { ref } from 'vue'
252263
import { ElMessage, ElMessageBox } from 'element-plus'
253264
import { VideoCameraFilled } from '@element-plus/icons-vue'
254265
import { toDoc } from '@/utils/doc'
266+
import ExportExcel from '@/components/exportExcel/exportExcel.vue'
267+
import ExportTemplate from '@/components/exportExcel/exportTemplate.vue'
268+
import ImportExcel from '@/components/exportExcel/importExcel.vue'
255269
256270
defineOptions({
257271
name: 'Api',

0 commit comments

Comments
 (0)