增加shift+鼠标左键定位代码功能,增加自动创建资源权限标识功能,细节调优。 (#1225)
* fix: 增加索引解决登录太慢的问题 * 增加shift+鼠标左键自动定位到编辑工具代码行的功能 * 过滤功能性标签 防止意外错误 * [utils\validator.go]:修复了当判断字符长度时,当字符串长度为中文,会判断错误。 * 增加资源标识 Co-authored-by: hexiang3000 <91460121+hexiang3000@users.noreply.github.com> Co-authored-by: fanyibo <29974992@qq.com>
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
"go.uber.org/zap"
|
||||
{{- if .NeedValid }}
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
{{- else if .AutoCreateResource}}
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
{{- end }}
|
||||
)
|
||||
|
||||
@@ -32,6 +34,9 @@ var {{.Abbreviation}}Service = service.ServiceGroupApp.{{.PackageT}}ServiceGroup
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.Package}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
{{- if .AutoCreateResource }}
|
||||
{{.Abbreviation}}.CreatedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
{{- if .NeedValid }}
|
||||
verify := utils.Rules{
|
||||
{{- range $index,$element := .Fields }}
|
||||
@@ -65,6 +70,9 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Con
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.Package}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
{{- if .AutoCreateResource }}
|
||||
{{.Abbreviation}}.DeletedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
if err := {{.Abbreviation}}Service.Delete{{.StructName}}({{.Abbreviation}}); err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
@@ -85,7 +93,10 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Con
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gin.Context) {
|
||||
var IDS request.IdsReq
|
||||
_ = c.ShouldBindJSON(&IDS)
|
||||
if err := {{.Abbreviation}}Service.Delete{{.StructName}}ByIds(IDS); err != nil {
|
||||
{{- if .AutoCreateResource }}
|
||||
deletedBy := utils.GetUserID(c)
|
||||
{{- end }}
|
||||
if err := {{.Abbreviation}}Service.Delete{{.StructName}}ByIds(IDS,deletedBy); err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
} else {
|
||||
@@ -105,6 +116,9 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gi
|
||||
func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Context) {
|
||||
var {{.Abbreviation}} {{.Package}}.{{.StructName}}
|
||||
_ = c.ShouldBindJSON(&{{.Abbreviation}})
|
||||
{{- if .AutoCreateResource }}
|
||||
{{.Abbreviation}}.UpdatedBy = utils.GetUserID(c)
|
||||
{{- end }}
|
||||
{{- if .NeedValid }}
|
||||
verify := utils.Rules{
|
||||
{{- range $index,$element := .Fields }}
|
||||
|
@@ -16,6 +16,11 @@ type {{.StructName}} struct {
|
||||
{{- else }}
|
||||
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}"`
|
||||
{{- end }} {{- end }}
|
||||
{{- if .AutoCreateResource }}
|
||||
CreatedBy uint `gorm:"column:created_by;comment:创建者"`
|
||||
UpdatedBy uint `gorm:"column:updated_by;comment:更新者"`
|
||||
DeletedBy uint `gorm:"column:deleted_by;comment:删除者"`
|
||||
{{- end}}
|
||||
}
|
||||
|
||||
{{ if .TableName }}
|
||||
|
@@ -5,6 +5,9 @@ import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/{{.Package}}"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
{{.Package}}Req "github.com/flipped-aurora/gin-vue-admin/server/model/{{.Package}}/request"
|
||||
{{- if .AutoCreateResource }}
|
||||
"gorm.io/gorm"
|
||||
{{- end}}
|
||||
)
|
||||
|
||||
type {{.StructName}}Service struct {
|
||||
@@ -20,14 +23,38 @@ func ({{.Abbreviation}}Service *{{.StructName}}Service) Create{{.StructName}}({{
|
||||
// Delete{{.StructName}} 删除{{.StructName}}记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}({{.Abbreviation}} {{.Package}}.{{.StructName}}) (err error) {
|
||||
{{- if .AutoCreateResource }}
|
||||
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Model(&{{.Package}}.{{.StructName}}{}).Where("id = ?", {{.Abbreviation}}.ID).Update("deleted_by", {{.Abbreviation}}.DeletedBy).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err = tx.Delete(&{{.Abbreviation}}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
{{- else }}
|
||||
err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error
|
||||
{{- end }}
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete{{.StructName}}ByIds 批量删除{{.StructName}}记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
|
||||
func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}ByIds(ids request.IdsReq,deleted_by uint) (err error) {
|
||||
{{- if .AutoCreateResource }}
|
||||
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Model(&{{.Package}}.{{.StructName}}{}).Where("id in ?", ids.Ids).Update("deleted_by", deleted_by).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Where("id in ?", ids.Ids).Delete(&{{.Package}}.{{.StructName}}{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
{{- else}}
|
||||
err = global.GVA_DB.Delete(&[]{{.Package}}.{{.StructName}}{},"id in ?",ids.Ids).Error
|
||||
{{- end}}
|
||||
return err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user