Skip to content

Commit e37fdb0

Browse files
committed
Merge branch 'master' into develop
2 parents ab2dd0c + ea693ef commit e37fdb0

25 files changed

+559
-37
lines changed

server/api/v1/sys_auto_code.go

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"gin-vue-admin/global"
77
"gin-vue-admin/model"
8+
"gin-vue-admin/model/request"
89
"gin-vue-admin/model/response"
910
"gin-vue-admin/service"
1011
"gin-vue-admin/utils"
@@ -15,6 +16,89 @@ import (
1516
"go.uber.org/zap"
1617
)
1718

19+
// @Tags AutoCode
20+
// @Summary 删除回滚记录
21+
// @Security ApiKeyAuth
22+
// @accept application/json
23+
// @Produce application/json
24+
// @Param data body request.AutoHistoryByID true "删除回滚记录"
25+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
26+
// @Router /autoCode/delSysHistory [post]
27+
func DelSysHistory(c *gin.Context) {
28+
var id request.AutoHistoryByID
29+
_ = c.ShouldBindJSON(&id)
30+
err := service.DeletePage(id.ID)
31+
if err != nil {
32+
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
33+
response.FailWithMessage("获取失败", c)
34+
}
35+
response.OkWithMessage("删除成功", c)
36+
37+
}
38+
39+
// @Tags AutoCode
40+
// @Summary 查询回滚记录
41+
// @Security ApiKeyAuth
42+
// @accept application/json
43+
// @Produce application/json
44+
// @Param data body request.SysAutoHistory true "查询回滚记录"
45+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
46+
// @Router /autoCode/getSysHistory [post]
47+
func GetSysHistory(c *gin.Context) {
48+
var search request.SysAutoHistory
49+
_ = c.ShouldBindJSON(&search)
50+
err, list, total := service.GetSysHistoryPage(search.PageInfo)
51+
if err != nil {
52+
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
53+
response.FailWithMessage("获取失败", c)
54+
} else {
55+
response.OkWithDetailed(response.PageResult{
56+
List: list,
57+
Total: total,
58+
Page: search.Page,
59+
PageSize: search.PageSize,
60+
}, "获取成功", c)
61+
}
62+
}
63+
64+
// @Tags AutoCode
65+
// @Summary 回滚
66+
// @Security ApiKeyAuth
67+
// @accept application/json
68+
// @Produce application/json
69+
// @Param data body request.AutoHistoryByID true "回滚自动生成代码"
70+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"回滚成功"}"
71+
// @Router /autoCode/rollback [post]
72+
func RollBack(c *gin.Context) {
73+
var id request.AutoHistoryByID
74+
_ = c.ShouldBindJSON(&id)
75+
if err := service.RollBack(id.ID); err != nil {
76+
response.FailWithMessage(err.Error(), c)
77+
return
78+
}
79+
response.OkWithMessage("回滚成功", c)
80+
}
81+
82+
// @Tags AutoCode
83+
// @Summary 回滚
84+
// @Security ApiKeyAuth
85+
// @accept application/json
86+
// @Produce application/json
87+
// @Param data body request.AutoHistoryByID true "获取meta信息"
88+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
89+
// @Router /autoCode/getMeta [post]
90+
func GetMeta(c *gin.Context) {
91+
var id request.AutoHistoryByID
92+
_ = c.ShouldBindJSON(&id)
93+
if v, err := service.GetMeta(id.ID); err != nil {
94+
response.FailWithMessage(err.Error(), c)
95+
return
96+
} else {
97+
response.OkWithDetailed(gin.H{"meta": v}, "获取成功", c)
98+
}
99+
100+
}
101+
18102
// @Tags AutoCode
19103
// @Summary 预览创建后的代码
20104
// @Security ApiKeyAuth
@@ -54,15 +138,18 @@ func CreateTemp(c *gin.Context) {
54138
response.FailWithMessage(err.Error(), c)
55139
return
56140
}
141+
var apiIds []uint
57142
if a.AutoCreateApiToSql {
58-
if err := service.AutoCreateApi(&a); err != nil {
143+
if ids, err := service.AutoCreateApi(&a); err != nil {
59144
global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Any("err", err))
60145
c.Writer.Header().Add("success", "false")
61146
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!"))
62147
return
148+
} else {
149+
apiIds = ids
63150
}
64151
}
65-
err := service.CreateTemp(a)
152+
err := service.CreateTemp(a, apiIds...)
66153
if err != nil {
67154
if errors.Is(err, model.AutoMoveErr) {
68155
c.Writer.Header().Add("success", "false")

server/global/global.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"gin-vue-admin/config"
1111

12-
"github.com/go-redis/redis"
12+
"github.com/go-redis/redis/v8"
1313
"github.com/spf13/viper"
1414
"gorm.io/gorm"
1515
)

server/go.mod

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ require (
2020
github.com/go-openapi/swag v0.19.8 // indirect
2121
github.com/go-playground/validator/v10 v10.3.0 // indirect
2222
github.com/go-redis/redis v6.15.7+incompatible
23+
github.com/go-redis/redis/v8 v8.11.0
2324
github.com/go-sql-driver/mysql v1.5.0
24-
github.com/golang/protobuf v1.4.2 // indirect
2525
github.com/gookit/color v1.3.1
2626
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
2727
github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84
@@ -31,8 +31,6 @@ require (
3131
github.com/mailru/easyjson v0.7.1 // indirect
3232
github.com/mitchellh/mapstructure v1.2.2 // indirect
3333
github.com/mojocn/base64Captcha v1.3.1
34-
github.com/onsi/ginkgo v1.7.0 // indirect
35-
github.com/onsi/gomega v1.4.3 // indirect
3634
github.com/pelletier/go-toml v1.6.0 // indirect
3735
github.com/pkg/errors v0.9.1 // indirect
3836
github.com/qiniu/api.v7/v7 v7.4.1
@@ -52,10 +50,8 @@ require (
5250
go.uber.org/zap v1.10.0
5351
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
5452
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
55-
golang.org/x/tools v0.0.0-20200324003944-a576cf524670 // indirect
5653
google.golang.org/protobuf v1.24.0 // indirect
5754
gopkg.in/ini.v1 v1.55.0 // indirect
58-
gopkg.in/yaml.v2 v2.3.0 // indirect
5955
gorm.io/driver/mysql v1.0.1
6056
gorm.io/gorm v1.20.7
6157
)

server/initialize/gorm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func MysqlTables(db *gorm.DB) {
4848
model.ExaSimpleUploader{},
4949
model.ExaCustomer{},
5050
model.SysOperationRecord{},
51-
51+
model.SysAutoCodeHistory{},
5252
// Code generated by gin-vue-admin Begin; DO NOT EDIT.
5353
// Code generated by gin-vue-admin End; DO NOT EDIT.
5454
)

server/initialize/redis.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package initialize
22

33
import (
4+
"context"
45
"gin-vue-admin/global"
5-
"github.com/go-redis/redis"
6+
7+
"github.com/go-redis/redis/v8"
68
"go.uber.org/zap"
79
)
810

@@ -13,7 +15,7 @@ func Redis() {
1315
Password: redisCfg.Password, // no password set
1416
DB: redisCfg.DB, // use default DB
1517
})
16-
pong, err := client.Ping().Result()
18+
pong, err := client.Ping(context.Background()).Result()
1719
if err != nil {
1820
global.GVA_LOG.Error("redis connect ping failed, err:", zap.Any("err", err))
1921
} else {

server/model/request/sys_autocode.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package request
22

3+
type SysAutoHistory struct {
4+
PageInfo
5+
}
6+
7+
type AutoHistoryByID struct {
8+
ID uint `json:"id"`
9+
}
10+
311
type DBReq struct {
412
Database string `json:"database" gorm:"column:database"`
513
}

server/model/sys_auto_code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type AutoCodeStruct struct {
77
StructName string `json:"structName"` // Struct名称
88
TableName string `json:"tableName"` // 表名
99
PackageName string `json:"packageName"` // 文件名称
10-
HumpPackageName string `json:"humpPackageName"` // go文件名称
10+
HumpPackageName string `json:"humpPackageName"` // go文件名称
1111
Abbreviation string `json:"abbreviation"` // Struct简称
1212
Description string `json:"description"` // Struct中文名称
1313
AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api

server/model/sys_autocode_history.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package model
2+
3+
import "gin-vue-admin/global"
4+
5+
// 自动迁移代码记录,用于回滚,重放使用
6+
7+
type SysAutoCodeHistory struct {
8+
global.GVA_MODEL
9+
TableName string `json:"tableName"`
10+
RequestMeta string `gorm:"type:text" json:"requestMeta,omitempty"` // 前端传入的结构化信息
11+
AutoCodePath string `gorm:"type:text" json:"autoCodePath,omitempty"` // 其他meta信息 path;path
12+
InjectionMeta string `gorm:"type:text" json:"injectionMeta,omitempty"` // 注入的内容 RouterPath@functionName@RouterString;
13+
StructName string `json:"structName"`
14+
StructCNName string `json:"structCNName"`
15+
ApiIDs string `json:"apiIDs,omitempty"` // api表注册内容
16+
Flag int `json:"flag"` // 表示对应状态 0 代表创建, 1 代表回滚 ...
17+
18+
}

server/router/sys_auto_code.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import (
88
func InitAutoCodeRouter(Router *gin.RouterGroup) {
99
AutoCodeRouter := Router.Group("autoCode")
1010
{
11-
AutoCodeRouter.POST("preview", v1.PreviewTemp) // 获取自动创建代码预览
12-
AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码
13-
AutoCodeRouter.GET("getTables", v1.GetTables) // 获取对应数据库的表
14-
AutoCodeRouter.GET("getDB", v1.GetDB) // 获取数据库
15-
AutoCodeRouter.GET("getColumn", v1.GetColumn) // 获取指定表所有字段信息
11+
AutoCodeRouter.POST("delSysHistory", v1.DelSysHistory) // 删除回滚记录
12+
AutoCodeRouter.POST("getMeta", v1.GetMeta) // 根据id获取meta信息
13+
AutoCodeRouter.POST("getSysHistory", v1.GetSysHistory) // 获取回滚记录分页
14+
AutoCodeRouter.POST("rollback", v1.RollBack) // 回滚
15+
AutoCodeRouter.POST("preview", v1.PreviewTemp) // 获取自动创建代码预览
16+
AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码
17+
AutoCodeRouter.GET("getTables", v1.GetTables) // 获取对应数据库的表
18+
AutoCodeRouter.GET("getDB", v1.GetDB) // 获取数据库
19+
AutoCodeRouter.GET("getColumn", v1.GetColumn) // 获取指定表所有字段信息
1620
}
1721
}

server/service/jwt_black_list.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package service
22

33
import (
4+
"context"
45
"errors"
56
"gin-vue-admin/global"
67
"gin-vue-admin/model"
7-
"gorm.io/gorm"
88
"time"
9+
10+
"gorm.io/gorm"
911
)
1012

1113
//@author: [piexlmax](https://github.com/piexlmax)
@@ -38,7 +40,7 @@ func IsBlacklist(jwt string) bool {
3840
//@return: err error, redisJWT string
3941

4042
func GetRedisJWT(userName string) (err error, redisJWT string) {
41-
redisJWT, err = global.GVA_REDIS.Get(userName).Result()
43+
redisJWT, err = global.GVA_REDIS.Get(context.Background(), userName).Result()
4244
return err, redisJWT
4345
}
4446

@@ -51,6 +53,6 @@ func GetRedisJWT(userName string) (err error, redisJWT string) {
5153
func SetRedisJWT(jwt string, userName string) (err error) {
5254
// 此处过期时间等于jwt过期时间
5355
timer := time.Duration(global.GVA_CONFIG.JWT.ExpiresTime) * time.Second
54-
err = global.GVA_REDIS.Set(userName, jwt, timer).Err()
56+
err = global.GVA_REDIS.Set(context.Background(), userName, jwt, timer).Err()
5557
return err
5658
}

server/service/sys_api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,7 @@ func DeleteApisByIds(ids request.IdsReq) (err error) {
141141
err = global.GVA_DB.Delete(&[]model.SysApi{}, "id in ?", ids.Ids).Error
142142
return err
143143
}
144+
145+
func DeleteApiByIds(ids []string) (err error) {
146+
return global.GVA_DB.Delete(model.SysApi{}, ids).Error
147+
}

0 commit comments

Comments
 (0)