From 259178ab7fb0162f352c7ec7dc93e68f42e6b10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E6=B7=BC=EF=BC=88piexlmax?= Date: Sun, 27 Dec 2020 17:46:53 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E4=BF=AE=E5=A4=8D=E4=BA=86swag?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=87=AA=E5=8A=A8=E5=8C=96=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84bug=EF=BC=9B=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E4=BA=86=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=9A=84swag=E9=83=A8=E5=88=86"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/sys_api.go | 2 +- server/api/v1/sys_operation_record.go | 13 +++++------ server/model/request/common.go | 7 +----- server/model/request/sys_operation_record.go | 18 ++------------- server/resource/template/server/api.go.tpl | 22 ++++++------------- server/resource/template/server/model.go.tpl | 11 +++------- .../resource/template/server/request.go.tpl | 12 +++------- .../resource/template/server/service.go.tpl | 2 +- .../template/web/workflowForm.vue.tpl | 1 - 9 files changed, 24 insertions(+), 64 deletions(-) diff --git a/server/api/v1/sys_api.go b/server/api/v1/sys_api.go index df2f9194..aa5d3bd3 100644 --- a/server/api/v1/sys_api.go +++ b/server/api/v1/sys_api.go @@ -110,7 +110,7 @@ func GetApiById(c *gin.Context) { } // @Tags SysApi -// @Summary 更新基础api +// @Summary 创建基础api // @Security ApiKeyAuth // @accept application/json // @Produce application/json diff --git a/server/api/v1/sys_operation_record.go b/server/api/v1/sys_operation_record.go index c239c523..d3d5745e 100644 --- a/server/api/v1/sys_operation_record.go +++ b/server/api/v1/sys_operation_record.go @@ -7,7 +7,6 @@ import ( "gin-vue-admin/model/response" "gin-vue-admin/service" "gin-vue-admin/utils" - "github.com/gin-gonic/gin" "go.uber.org/zap" ) @@ -17,7 +16,7 @@ import ( // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.SysOperationRecordCreate true "创建SysOperationRecord" +// @Param data body model.SysOperationRecord true "创建SysOperationRecord" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /sysOperationRecord/createSysOperationRecord [post] func CreateSysOperationRecord(c *gin.Context) { @@ -36,7 +35,7 @@ func CreateSysOperationRecord(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.GetByIdUint true "SysOperationRecord模型" +// @Param data body model.SysOperationRecord true "SysOperationRecord模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /sysOperationRecord/deleteSysOperationRecord [delete] func DeleteSysOperationRecord(c *gin.Context) { @@ -74,17 +73,17 @@ func DeleteSysOperationRecordByIds(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data query request.GetByIdUint false "编号" +// @Param data body model.SysOperationRecord true "Id" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Router /sysOperationRecord/findSysOperationRecord [get] func FindSysOperationRecord(c *gin.Context) { - var sysOperationRecord request.GetByIdUint + var sysOperationRecord model.SysOperationRecord _ = c.ShouldBindQuery(&sysOperationRecord) if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) 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)) response.FailWithMessage("查询失败", c) } else { @@ -97,7 +96,7 @@ func FindSysOperationRecord(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data query request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件" +// @Param data body request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /sysOperationRecord/getSysOperationRecordList [get] func GetSysOperationRecordList(c *gin.Context) { diff --git a/server/model/request/common.go b/server/model/request/common.go index f9a92e84..a7c542e6 100644 --- a/server/model/request/common.go +++ b/server/model/request/common.go @@ -11,11 +11,6 @@ type GetById struct { Id float64 `json:"id" form:"id"` } -// Find by id structure -type GetByIdUint struct { - Id uint `json:"id" form:"id"` -} - type IdsReq struct { Ids []int `json:"ids" form:"ids"` } @@ -25,4 +20,4 @@ type GetAuthorityId struct { AuthorityId string } -type Empty struct{} +type Empty struct {} \ No newline at end of file diff --git a/server/model/request/sys_operation_record.go b/server/model/request/sys_operation_record.go index 535c2e39..a9b7abbe 100644 --- a/server/model/request/sys_operation_record.go +++ b/server/model/request/sys_operation_record.go @@ -1,22 +1,8 @@ package request -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"` -} +import "gin-vue-admin/model" type SysOperationRecordSearch struct { - SysOperationRecordCreate + model.SysOperationRecord PageInfo } diff --git a/server/resource/template/server/api.go.tpl b/server/resource/template/server/api.go.tpl index 41509917..fc6dd04a 100644 --- a/server/resource/template/server/api.go.tpl +++ b/server/resource/template/server/api.go.tpl @@ -15,7 +15,7 @@ import ( // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.{{.StructName}}Base true "创建{{.StructName}}" +// @Param data body model.{{.StructName}} true "创建{{.StructName}}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /{{.Abbreviation}}/create{{.StructName}} [post] func Create{{.StructName}}(c *gin.Context) { @@ -34,7 +34,7 @@ func Create{{.StructName}}(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.GetByIdUint true "删除{{.StructName}}" +// @Param data body model.{{.StructName}} true "删除{{.StructName}}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /{{.Abbreviation}}/delete{{.StructName}} [delete] func Delete{{.StructName}}(c *gin.Context) { @@ -72,20 +72,12 @@ func Delete{{.StructName}}ByIds(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.{{.StructName}}Update true "更新{{.StructName}}" +// @Param data body model.{{.StructName}} true "更新{{.StructName}}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /{{.Abbreviation}}/update{{.StructName}} [put] func Update{{.StructName}}(c *gin.Context) { var {{.Abbreviation}} model.{{.StructName}} _ = 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 { global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) response.FailWithMessage("更新失败", c) @@ -99,13 +91,13 @@ func Update{{.StructName}}(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data query request.GetByIdUint true "用id查询{{.StructName}}" +// @Param data body model.{{.StructName}} true "用id查询{{.StructName}}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Router /{{.Abbreviation}}/find{{.StructName}} [get] func Find{{.StructName}}(c *gin.Context) { - var {{.Abbreviation}} request.GetByIdUint + var {{.Abbreviation}} model.{{.StructName}} _ = 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)) response.FailWithMessage("查询失败", c) } else { @@ -118,7 +110,7 @@ func Find{{.StructName}}(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data query request.{{.StructName}}Search true "分页获取{{.StructName}}列表" +// @Param data body request.{{.StructName}}Search true "分页获取{{.StructName}}列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /{{.Abbreviation}}/get{{.StructName}}List [get] func Get{{.StructName}}List(c *gin.Context) { diff --git a/server/resource/template/server/model.go.tpl b/server/resource/template/server/model.go.tpl index e27f01e6..2ca70d38 100644 --- a/server/resource/template/server/model.go.tpl +++ b/server/resource/template/server/model.go.tpl @@ -6,8 +6,8 @@ import ( ) // 如果含有time.Time 请自行import time包 -type {{.StructName}}Base struct { - {{- range .Fields}} +type {{.StructName}} struct { + global.GVA_MODEL {{- range .Fields}} {{- 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 -}}"` {{- else }} @@ -15,14 +15,9 @@ type {{.StructName}}Base struct { {{- end }} {{- end }} } -type {{.StructName}} struct { - global.GVA_MODEL - {{.StructName}}Base -} - {{ if .TableName }} func ({{.StructName}}) TableName() string { - return "{{.TableName}}" + return "{{.TableName}}" } {{ end }} diff --git a/server/resource/template/server/request.go.tpl b/server/resource/template/server/request.go.tpl index 457d65ab..68cc026d 100644 --- a/server/resource/template/server/request.go.tpl +++ b/server/resource/template/server/request.go.tpl @@ -2,13 +2,7 @@ package request import "gin-vue-admin/model" -type {{.StructName}}Search struct { - model.{{.StructName}}Base +type {{.StructName}}Search struct{ + model.{{.StructName}} PageInfo -} - -type {{.StructName}}Update struct { - model.{{.StructName}}Base - ID uint `gorm:"primarykey"` -} - +} \ No newline at end of file diff --git a/server/resource/template/server/service.go.tpl b/server/resource/template/server/service.go.tpl index 2137b06e..323f7956 100644 --- a/server/resource/template/server/service.go.tpl +++ b/server/resource/template/server/service.go.tpl @@ -35,7 +35,7 @@ func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) //@return: 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 } diff --git a/server/resource/template/web/workflowForm.vue.tpl b/server/resource/template/web/workflowForm.vue.tpl index e5778df8..ae312026 100644 --- a/server/resource/template/web/workflowForm.vue.tpl +++ b/server/resource/template/web/workflowForm.vue.tpl @@ -117,7 +117,6 @@ export default { return false } } - return true }, ...mapGetters("user", ["userInfo"]) },