Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
songzhibin97 committed Jul 20, 2021
2 parents ab2dd0c + ea693ef commit e37fdb0
Show file tree
Hide file tree
Showing 25 changed files with 559 additions and 37 deletions.
91 changes: 89 additions & 2 deletions server/api/v1/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
Expand All @@ -15,6 +16,89 @@ import (
"go.uber.org/zap"
)

// @Tags AutoCode
// @Summary 删除回滚记录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AutoHistoryByID true "删除回滚记录"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /autoCode/delSysHistory [post]
func DelSysHistory(c *gin.Context) {
var id request.AutoHistoryByID
_ = c.ShouldBindJSON(&id)
err := service.DeletePage(id.ID)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
}
response.OkWithMessage("删除成功", c)

}

// @Tags AutoCode
// @Summary 查询回滚记录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysAutoHistory true "查询回滚记录"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getSysHistory [post]
func GetSysHistory(c *gin.Context) {
var search request.SysAutoHistory
_ = c.ShouldBindJSON(&search)
err, list, total := service.GetSysHistoryPage(search.PageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: search.Page,
PageSize: search.PageSize,
}, "获取成功", c)
}
}

// @Tags AutoCode
// @Summary 回滚
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AutoHistoryByID true "回滚自动生成代码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"回滚成功"}"
// @Router /autoCode/rollback [post]
func RollBack(c *gin.Context) {
var id request.AutoHistoryByID
_ = c.ShouldBindJSON(&id)
if err := service.RollBack(id.ID); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("回滚成功", c)
}

// @Tags AutoCode
// @Summary 回滚
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AutoHistoryByID true "获取meta信息"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getMeta [post]
func GetMeta(c *gin.Context) {
var id request.AutoHistoryByID
_ = c.ShouldBindJSON(&id)
if v, err := service.GetMeta(id.ID); err != nil {
response.FailWithMessage(err.Error(), c)
return
} else {
response.OkWithDetailed(gin.H{"meta": v}, "获取成功", c)
}

}

// @Tags AutoCode
// @Summary 预览创建后的代码
// @Security ApiKeyAuth
Expand Down Expand Up @@ -54,15 +138,18 @@ func CreateTemp(c *gin.Context) {
response.FailWithMessage(err.Error(), c)
return
}
var apiIds []uint
if a.AutoCreateApiToSql {
if err := service.AutoCreateApi(&a); err != nil {
if ids, err := service.AutoCreateApi(&a); err != nil {
global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Any("err", err))
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!"))
return
} else {
apiIds = ids
}
}
err := service.CreateTemp(a)
err := service.CreateTemp(a, apiIds...)
if err != nil {
if errors.Is(err, model.AutoMoveErr) {
c.Writer.Header().Add("success", "false")
Expand Down
2 changes: 1 addition & 1 deletion server/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"gin-vue-admin/config"

"github.com/go-redis/redis"
"github.com/go-redis/redis/v8"
"github.com/spf13/viper"
"gorm.io/gorm"
)
Expand Down
6 changes: 1 addition & 5 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ require (
github.com/go-openapi/swag v0.19.8 // indirect
github.com/go-playground/validator/v10 v10.3.0 // indirect
github.com/go-redis/redis v6.15.7+incompatible
github.com/go-redis/redis/v8 v8.11.0
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.2 // indirect
github.com/gookit/color v1.3.1
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84
Expand All @@ -31,8 +31,6 @@ require (
github.com/mailru/easyjson v0.7.1 // indirect
github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/mojocn/base64Captcha v1.3.1
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/qiniu/api.v7/v7 v7.4.1
Expand All @@ -52,10 +50,8 @@ require (
go.uber.org/zap v1.10.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/tools v0.0.0-20200324003944-a576cf524670 // indirect
google.golang.org/protobuf v1.24.0 // indirect
gopkg.in/ini.v1 v1.55.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gorm.io/driver/mysql v1.0.1
gorm.io/gorm v1.20.7
)
2 changes: 1 addition & 1 deletion server/initialize/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func MysqlTables(db *gorm.DB) {
model.ExaSimpleUploader{},
model.ExaCustomer{},
model.SysOperationRecord{},

model.SysAutoCodeHistory{},
// Code generated by gin-vue-admin Begin; DO NOT EDIT.
// Code generated by gin-vue-admin End; DO NOT EDIT.
)
Expand Down
6 changes: 4 additions & 2 deletions server/initialize/redis.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package initialize

import (
"context"
"gin-vue-admin/global"
"github.com/go-redis/redis"

"github.com/go-redis/redis/v8"
"go.uber.org/zap"
)

Expand All @@ -13,7 +15,7 @@ func Redis() {
Password: redisCfg.Password, // no password set
DB: redisCfg.DB, // use default DB
})
pong, err := client.Ping().Result()
pong, err := client.Ping(context.Background()).Result()
if err != nil {
global.GVA_LOG.Error("redis connect ping failed, err:", zap.Any("err", err))
} else {
Expand Down
8 changes: 8 additions & 0 deletions server/model/request/sys_autocode.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package request

type SysAutoHistory struct {
PageInfo
}

type AutoHistoryByID struct {
ID uint `json:"id"`
}

type DBReq struct {
Database string `json:"database" gorm:"column:database"`
}
Expand Down
2 changes: 1 addition & 1 deletion server/model/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type AutoCodeStruct struct {
StructName string `json:"structName"` // Struct名称
TableName string `json:"tableName"` // 表名
PackageName string `json:"packageName"` // 文件名称
HumpPackageName string `json:"humpPackageName"` // go文件名称
HumpPackageName string `json:"humpPackageName"` // go文件名称
Abbreviation string `json:"abbreviation"` // Struct简称
Description string `json:"description"` // Struct中文名称
AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api
Expand Down
18 changes: 18 additions & 0 deletions server/model/sys_autocode_history.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package model

import "gin-vue-admin/global"

// 自动迁移代码记录,用于回滚,重放使用

type SysAutoCodeHistory struct {
global.GVA_MODEL
TableName string `json:"tableName"`
RequestMeta string `gorm:"type:text" json:"requestMeta,omitempty"` // 前端传入的结构化信息
AutoCodePath string `gorm:"type:text" json:"autoCodePath,omitempty"` // 其他meta信息 path;path
InjectionMeta string `gorm:"type:text" json:"injectionMeta,omitempty"` // 注入的内容 RouterPath@functionName@RouterString;
StructName string `json:"structName"`
StructCNName string `json:"structCNName"`
ApiIDs string `json:"apiIDs,omitempty"` // api表注册内容
Flag int `json:"flag"` // 表示对应状态 0 代表创建, 1 代表回滚 ...

}
14 changes: 9 additions & 5 deletions server/router/sys_auto_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
func InitAutoCodeRouter(Router *gin.RouterGroup) {
AutoCodeRouter := Router.Group("autoCode")
{
AutoCodeRouter.POST("preview", v1.PreviewTemp) // 获取自动创建代码预览
AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码
AutoCodeRouter.GET("getTables", v1.GetTables) // 获取对应数据库的表
AutoCodeRouter.GET("getDB", v1.GetDB) // 获取数据库
AutoCodeRouter.GET("getColumn", v1.GetColumn) // 获取指定表所有字段信息
AutoCodeRouter.POST("delSysHistory", v1.DelSysHistory) // 删除回滚记录
AutoCodeRouter.POST("getMeta", v1.GetMeta) // 根据id获取meta信息
AutoCodeRouter.POST("getSysHistory", v1.GetSysHistory) // 获取回滚记录分页
AutoCodeRouter.POST("rollback", v1.RollBack) // 回滚
AutoCodeRouter.POST("preview", v1.PreviewTemp) // 获取自动创建代码预览
AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码
AutoCodeRouter.GET("getTables", v1.GetTables) // 获取对应数据库的表
AutoCodeRouter.GET("getDB", v1.GetDB) // 获取数据库
AutoCodeRouter.GET("getColumn", v1.GetColumn) // 获取指定表所有字段信息
}
}
8 changes: 5 additions & 3 deletions server/service/jwt_black_list.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package service

import (
"context"
"errors"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gorm.io/gorm"
"time"

"gorm.io/gorm"
)

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

func GetRedisJWT(userName string) (err error, redisJWT string) {
redisJWT, err = global.GVA_REDIS.Get(userName).Result()
redisJWT, err = global.GVA_REDIS.Get(context.Background(), userName).Result()
return err, redisJWT
}

Expand All @@ -51,6 +53,6 @@ func GetRedisJWT(userName string) (err error, redisJWT string) {
func SetRedisJWT(jwt string, userName string) (err error) {
// 此处过期时间等于jwt过期时间
timer := time.Duration(global.GVA_CONFIG.JWT.ExpiresTime) * time.Second
err = global.GVA_REDIS.Set(userName, jwt, timer).Err()
err = global.GVA_REDIS.Set(context.Background(), userName, jwt, timer).Err()
return err
}
4 changes: 4 additions & 0 deletions server/service/sys_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,7 @@ func DeleteApisByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]model.SysApi{}, "id in ?", ids.Ids).Error
return err
}

func DeleteApiByIds(ids []string) (err error) {
return global.GVA_DB.Delete(model.SysApi{}, ids).Error
}
Loading

0 comments on commit e37fdb0

Please sign in to comment.