From 946b51c960d84f34cb662df6b2b640b42578c0ec Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Sat, 10 Jul 2021 19:01:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/sys_auto_code.go | 30 ++++++++++++++++++++++++-- server/model/request/sys_autocode.go | 8 +++++++ server/model/sys_auto_code.go | 4 ---- server/router/sys_auto_code.go | 1 + server/service/sys_autocode_history.go | 12 +++++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/server/api/v1/sys_auto_code.go b/server/api/v1/sys_auto_code.go index b61c1ccf..d0e2ce20 100644 --- a/server/api/v1/sys_auto_code.go +++ b/server/api/v1/sys_auto_code.go @@ -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" @@ -15,16 +16,41 @@ import ( "go.uber.org/zap" ) +// @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/preview [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 uint true "回滚自动生成代码" +// @Param data body request.AutoHistoryByID true "回滚自动生成代码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"回滚成功"}" // @Router /autoCode/preview [post] func RollBack(c *gin.Context) { - var id model.AutoHistoryByID + var id request.AutoHistoryByID _ = c.ShouldBindJSON(&id) if err := service.RollBack(id.ID); err != nil { response.FailWithMessage(err.Error(), c) diff --git a/server/model/request/sys_autocode.go b/server/model/request/sys_autocode.go index d97be350..2e64eb9a 100644 --- a/server/model/request/sys_autocode.go +++ b/server/model/request/sys_autocode.go @@ -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"` } diff --git a/server/model/sys_auto_code.go b/server/model/sys_auto_code.go index 5222a9fb..73b68f43 100644 --- a/server/model/sys_auto_code.go +++ b/server/model/sys_auto_code.go @@ -2,10 +2,6 @@ package model import "errors" -type AutoHistoryByID struct { - ID uint `json:"id"` -} - // 初始版本自动化代码工具 type AutoCodeStruct struct { StructName string `json:"structName"` // Struct名称 diff --git a/server/router/sys_auto_code.go b/server/router/sys_auto_code.go index f81bd8f6..c39605b7 100644 --- a/server/router/sys_auto_code.go +++ b/server/router/sys_auto_code.go @@ -8,6 +8,7 @@ import ( func InitAutoCodeRouter(Router *gin.RouterGroup) { AutoCodeRouter := Router.Group("autoCode") { + AutoCodeRouter.POST("getSysHistory", v1.GetSysHistory) // 获取回滚记录分页 AutoCodeRouter.POST("rollback", v1.RollBack) // 回滚 AutoCodeRouter.POST("preview", v1.PreviewTemp) // 获取自动创建代码预览 AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码 diff --git a/server/service/sys_autocode_history.go b/server/service/sys_autocode_history.go index fbbef8d4..985cb612 100644 --- a/server/service/sys_autocode_history.go +++ b/server/service/sys_autocode_history.go @@ -4,6 +4,7 @@ import ( "errors" "gin-vue-admin/global" "gin-vue-admin/model" + "gin-vue-admin/model/request" "gin-vue-admin/utils" "strings" @@ -20,6 +21,7 @@ func CreateAutoCodeHistory(autoCodeMeta string, injectionMeta string, tableName }).Error } +// RollBack 回滚 func RollBack(id uint) error { md := model.SysAutoCodeHistory{} if err := global.GVA_DB.First(&md, id).Error; err != nil { @@ -61,3 +63,13 @@ func RollBack(id uint) error { md.Flag = 1 return global.GVA_DB.Save(&md).Error } + +func GetSysHistoryPage(info request.PageInfo) (err error, list interface{}, total int64) { + limit := info.PageSize + offset := info.PageSize * (info.Page - 1) + db := global.GVA_DB + var fileLists []model.SysAutoCodeHistory + err = db.Find(&fileLists).Count(&total).Error + err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&fileLists).Error + return err, fileLists, total +}