提交 a48c77e2 编写于 作者: 天魔老师's avatar 天魔老师

autocode 修复swag相关功能

上级 415142e2
...@@ -110,7 +110,7 @@ func GetApiById(c *gin.Context) { ...@@ -110,7 +110,7 @@ func GetApiById(c *gin.Context) {
} }
// @Tags SysApi // @Tags SysApi
// @Summary 创建基础api // @Summary 更新基础api
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"gin-vue-admin/model/response" "gin-vue-admin/model/response"
"gin-vue-admin/service" "gin-vue-admin/service"
"gin-vue-admin/utils" "gin-vue-admin/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
) )
...@@ -16,7 +17,7 @@ import ( ...@@ -16,7 +17,7 @@ import (
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body model.SysOperationRecord true "创建SysOperationRecord" // @Param data body request.SysOperationRecordCreate true "创建SysOperationRecord"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysOperationRecord/createSysOperationRecord [post] // @Router /sysOperationRecord/createSysOperationRecord [post]
func CreateSysOperationRecord(c *gin.Context) { func CreateSysOperationRecord(c *gin.Context) {
...@@ -35,7 +36,7 @@ func CreateSysOperationRecord(c *gin.Context) { ...@@ -35,7 +36,7 @@ func CreateSysOperationRecord(c *gin.Context) {
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body model.SysOperationRecord true "SysOperationRecord模型" // @Param data body request.SysOperationRecordCreate true "SysOperationRecord模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecord [delete] // @Router /sysOperationRecord/deleteSysOperationRecord [delete]
func DeleteSysOperationRecord(c *gin.Context) { func DeleteSysOperationRecord(c *gin.Context) {
...@@ -73,17 +74,17 @@ func DeleteSysOperationRecordByIds(c *gin.Context) { ...@@ -73,17 +74,17 @@ func DeleteSysOperationRecordByIds(c *gin.Context) {
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body model.SysOperationRecord true "Id" // @Param data query request.GetByIdUnit false "编号"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysOperationRecord/findSysOperationRecord [get] // @Router /sysOperationRecord/findSysOperationRecord [get]
func FindSysOperationRecord(c *gin.Context) { func FindSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord var sysOperationRecord request.GetByIdUnit
_ = c.ShouldBindQuery(&sysOperationRecord) _ = c.ShouldBindQuery(&sysOperationRecord)
if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil { if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID); err != nil { if err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.Id); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err)) global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c) response.FailWithMessage("查询失败", c)
} else { } else {
...@@ -96,7 +97,7 @@ func FindSysOperationRecord(c *gin.Context) { ...@@ -96,7 +97,7 @@ func FindSysOperationRecord(c *gin.Context) {
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件" // @Param data query request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysOperationRecord/getSysOperationRecordList [get] // @Router /sysOperationRecord/getSysOperationRecordList [get]
func GetSysOperationRecordList(c *gin.Context) { func GetSysOperationRecordList(c *gin.Context) {
......
...@@ -11,6 +11,11 @@ type GetById struct { ...@@ -11,6 +11,11 @@ type GetById struct {
Id float64 `json:"id" form:"id"` Id float64 `json:"id" form:"id"`
} }
// Find by id structure
type GetByIdUnit struct {
Id uint `json:"id" form:"id"`
}
type IdsReq struct { type IdsReq struct {
Ids []int `json:"ids" form:"ids"` Ids []int `json:"ids" form:"ids"`
} }
...@@ -20,4 +25,4 @@ type GetAuthorityId struct { ...@@ -20,4 +25,4 @@ type GetAuthorityId struct {
AuthorityId string AuthorityId string
} }
type Empty struct {} type Empty struct{}
\ No newline at end of file
package request package request
import "gin-vue-admin/model" import "gin-vue-admin/global"
type SysOperationRecordCreate struct {
global.GVA_MODEL
Ip string `json:"ip" form:"ip" gorm:"column:ip;comment:请求ip"`
Method string `json:"method" form:"method" gorm:"column:method;comment:请求方法"`
Path string `json:"path" form:"path" gorm:"column:path;comment:请求路径"`
Status int `json:"status" form:"status" gorm:"column:status;comment:请求状态"`
Latency int `json:"latency" form:"latency" gorm:"column:latency;comment:延迟"`
Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:代理"`
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"`
Body string `json:"body" form:"body" gorm:"type:longtext;column:body;comment:请求Body"`
Resp string `json:"resp" form:"resp" gorm:"type:longtext;column:resp;comment:响应Body"`
UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"`
}
type SysOperationRecordSearch struct { type SysOperationRecordSearch struct {
model.SysOperationRecord SysOperationRecordCreate
PageInfo PageInfo
} }
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body model.{{.StructName}} true "创建{{.StructName}}" // @Param data body model.{{.StructName}}Base true "创建{{.StructName}}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /{{.Abbreviation}}/create{{.StructName}} [post] // @Router /{{.Abbreviation}}/create{{.StructName}} [post]
func Create{{.StructName}}(c *gin.Context) { func Create{{.StructName}}(c *gin.Context) {
...@@ -34,7 +34,7 @@ func Create{{.StructName}}(c *gin.Context) { ...@@ -34,7 +34,7 @@ func Create{{.StructName}}(c *gin.Context) {
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body model.{{.StructName}} true "删除{{.StructName}}" // @Param data body request.GetByIdUnit true "删除{{.StructName}}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /{{.Abbreviation}}/delete{{.StructName}} [delete] // @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
func Delete{{.StructName}}(c *gin.Context) { func Delete{{.StructName}}(c *gin.Context) {
...@@ -72,12 +72,20 @@ func Delete{{.StructName}}ByIds(c *gin.Context) { ...@@ -72,12 +72,20 @@ func Delete{{.StructName}}ByIds(c *gin.Context) {
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body model.{{.StructName}} true "更新{{.StructName}}" // @Param data body request.{{.StructName}}Update true "更新{{.StructName}}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /{{.Abbreviation}}/update{{.StructName}} [put] // @Router /{{.Abbreviation}}/update{{.StructName}} [put]
func Update{{.StructName}}(c *gin.Context) { func Update{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}} var {{.Abbreviation}} model.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}}) _ = c.ShouldBindJSON(&{{.Abbreviation}})
err, {{.Abbreviation}}Original := service.Get{{.StructName}}({{.Abbreviation}}.ID)
if err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
}
{{.Abbreviation}}.CreatedAt = {{.Abbreviation}}Original.CreatedAt
if err := service.Update{{.StructName}}({{.Abbreviation}}); err != nil { if err := service.Update{{.StructName}}({{.Abbreviation}}); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c) response.FailWithMessage("更新失败", c)
...@@ -91,13 +99,13 @@ func Update{{.StructName}}(c *gin.Context) { ...@@ -91,13 +99,13 @@ func Update{{.StructName}}(c *gin.Context) {
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body model.{{.StructName}} true "用id查询{{.StructName}}" // @Param data query request.GetByIdUnit true "用id查询{{.StructName}}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /{{.Abbreviation}}/find{{.StructName}} [get] // @Router /{{.Abbreviation}}/find{{.StructName}} [get]
func Find{{.StructName}}(c *gin.Context) { func Find{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}} var {{.Abbreviation}} request.GetByIdUnit
_ = c.ShouldBindQuery(&{{.Abbreviation}}) _ = c.ShouldBindQuery(&{{.Abbreviation}})
if err, re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil { if err, re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.Id); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err)) global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c) response.FailWithMessage("查询失败", c)
} else { } else {
...@@ -110,7 +118,7 @@ func Find{{.StructName}}(c *gin.Context) { ...@@ -110,7 +118,7 @@ func Find{{.StructName}}(c *gin.Context) {
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body request.{{.StructName}}Search true "分页获取{{.StructName}}列表" // @Param data query request.{{.StructName}}Search true "分页获取{{.StructName}}列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /{{.Abbreviation}}/get{{.StructName}}List [get] // @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
func Get{{.StructName}}List(c *gin.Context) { func Get{{.StructName}}List(c *gin.Context) {
......
...@@ -6,8 +6,8 @@ import ( ...@@ -6,8 +6,8 @@ import (
) )
// 如果含有time.Time 请自行import time包 // 如果含有time.Time 请自行import time包
type {{.StructName}} struct { type {{.StructName}}Base struct {
global.GVA_MODEL {{- range .Fields}} {{- range .Fields}}
{{- if eq .FieldType "bool" }} {{- if eq .FieldType "bool" }}
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if eq .FieldType "string" -}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"` {{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if eq .FieldType "string" -}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
{{- else }} {{- else }}
...@@ -15,9 +15,14 @@ type {{.StructName}} struct { ...@@ -15,9 +15,14 @@ type {{.StructName}} struct {
{{- end }} {{- end }} {{- end }} {{- end }}
} }
type {{.StructName}} struct {
global.GVA_MODEL
{{.StructName}}Base
}
{{ if .TableName }} {{ if .TableName }}
func ({{.StructName}}) TableName() string { func ({{.StructName}}) TableName() string {
return "{{.TableName}}" return "{{.TableName}}"
} }
{{ end }} {{ end }}
......
...@@ -2,7 +2,13 @@ package request ...@@ -2,7 +2,13 @@ package request
import "gin-vue-admin/model" import "gin-vue-admin/model"
type {{.StructName}}Search struct{ type {{.StructName}}Search struct {
model.{{.StructName}} model.{{.StructName}}Base
PageInfo PageInfo
} }
\ No newline at end of file
type {{.StructName}}Update struct {
model.{{.StructName}}Base
ID uint `gorm:"primarykey"`
}
...@@ -35,7 +35,7 @@ func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) ...@@ -35,7 +35,7 @@ func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error)
//@return: err error //@return: err error
func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) { func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error err = global.GVA_DB.Delete(&[]model.{{.StructName}}{}, "id in ?", ids.Ids).Error
return err return err
} }
......
...@@ -117,6 +117,7 @@ export default { ...@@ -117,6 +117,7 @@ export default {
return false return false
} }
} }
return true
}, },
...mapGetters("user", ["userInfo"]) ...mapGetters("user", ["userInfo"])
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册