增加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:
奇淼(piexlmax
2022-09-21 21:42:10 +08:00
committed by GitHub
parent b5c79be625
commit ef35c53712
15 changed files with 228 additions and 13 deletions

View File

@@ -198,4 +198,4 @@ cors:
allow-headers: content-type
allow-methods: GET, POST
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type
allow-credentials: true # 布尔值
allow-credentials: true # 布尔值

View File

@@ -17,6 +17,7 @@ type AutoCodeStruct struct {
Abbreviation string `json:"abbreviation"` // Struct简称
Description string `json:"description"` // Struct中文名称
AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api
AutoCreateResource bool `json:"autoCreateResource"` // 是否自动创建资源标识
AutoMoveFile bool `json:"autoMoveFile"` // 是否自动移动文件
Fields []*Field `json:"fields,omitempty"`
HasTimer bool

View File

@@ -7,8 +7,8 @@ import (
type SysUser struct {
global.GVA_MODEL
UUID uuid.UUID `json:"uuid" gorm:"comment:用户UUID"` // 用户UUID
Username string `json:"userName" gorm:"comment:用户登录名"` // 用户登录名
UUID uuid.UUID `json:"uuid" gorm:"index;comment:用户UUID"` // 用户UUID
Username string `json:"userName" gorm:"index;comment:用户登录名"` // 用户登录名
Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
SideMode string `json:"sideMode" gorm:"default:dark;comment:用户侧边主题"` // 用户侧边主题

View File

@@ -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 }}

View File

@@ -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 }}

View File

@@ -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
}

View File

@@ -38,11 +38,11 @@ func NotEmpty() string {
return "notEmpty"
}
//@author: [zooqkl](https://github.com/zooqkl)
//@function: RegexpMatch
//@description: 正则校验 校验输入项是否满足正则表达式
//@param: rule string
//@return: string
// @author: [zooqkl](https://github.com/zooqkl)
// @function: RegexpMatch
// @description: 正则校验 校验输入项是否满足正则表达式
// @param: rule string
// @return: string
func RegexpMatch(rule string) string {
return "regexp=" + rule
}
@@ -166,7 +166,9 @@ func Verify(st interface{}, roleMap Rules) (err error) {
func compareVerify(value reflect.Value, VerifyStr string) bool {
switch value.Kind() {
case reflect.String, reflect.Slice, reflect.Array:
case reflect.String:
return compare(len([]rune(value.String())), VerifyStr)
case reflect.Slice, reflect.Array:
return compare(value.Len(), VerifyStr)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return compare(value.Uint(), VerifyStr)
@@ -187,7 +189,7 @@ func compareVerify(value reflect.Value, VerifyStr string) bool {
func isBlank(value reflect.Value) bool {
switch value.Kind() {
case reflect.String:
case reflect.String, reflect.Slice:
return value.Len() == 0
case reflect.Bool:
return !value.Bool()