fix:tpl bug

This commit is contained in:
zhangwenjian committed 2020-09-12 20:06:13 +08:00
1 parent 31544ff1ae
commit 0b80ac635d
6 files changed
+14 -14

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
package models
//casbin_rule
//sys_casbin_rule
type CasbinRule struct {
PType string `json:"p_type" gorm:"size:100;"`
V0 string `json:"v0" gorm:"size:100;"`
+1 -1
View File
@@ -84,5 +84,5 @@ func InitData(db *gorm.DB) {
{"p", "admin", "/api/v1/syssetting/:id", "DELETE", "", "", ""},
}
db.Table("casbin_rule").Create(list)
db.Table("sys_casbin_rule").Create(list)
}
+1 -1
View File
@@ -215,7 +215,7 @@ func (role *SysRole) BatchDelete(id []int) (Result bool, err error) {
// 删除casbin配置
for i := 0; i < len(roles); i++ {
if err := tx.Table("casbin_rule").Where("v0 in (?)", roles[0].RoleKey).Delete(&CasbinRule{}).Error; err != nil {
if err := tx.Table("sys_casbin_rule").Where("v0 in (?)", roles[0].RoleKey).Delete(&CasbinRule{}).Error; err != nil {
tx.Rollback()
return false, err
}
+5 -5
View File
@@ -90,7 +90,7 @@ func (rm *RoleMenu) DeleteRoleMenu(roleId int) (bool, error) {
tx.Rollback()
return false, err
}
sql3 := "delete from casbin_rule where v0= '" + role.RoleKey + "';"
sql3 := "delete from sys_casbin_rule where v0= '" + role.RoleKey + "';"
if err := tx.Exec(sql3).Error; err != nil {
tx.Rollback()
return false, err
@@ -127,7 +127,7 @@ func (rm *RoleMenu) BatchDeleteRoleMenu(roleIds []int) (bool, error) {
}
sql := ""
for i := 0; i < len(role); i++ {
sql += "delete from casbin_rule where v0= '" + role[i].RoleName + "';"
sql += "delete from sys_casbin_rule where v0= '" + role[i].RoleName + "';"
}
if err := tx.Exec(sql).Error; err != nil {
tx.Rollback()
@@ -170,7 +170,7 @@ func (rm *RoleMenu) Insert(roleId int, menuId []int) (bool, error) {
}
//ORM不支持批量插入所以需要拼接 sql 串
sysRoleMenuSql := "INSERT INTO `sys_role_menu` (`role_id`,`menu_id`,`role_name`) VALUES "
casbinRuleSql := "INSERT INTO `casbin_rule` (`p_type`,`v0`,`v1`,`v2`) VALUES "
casbinRuleSql := "INSERT INTO `sys_casbin_rule` (`p_type`,`v0`,`v1`,`v2`) VALUES "
for i, m := range menu {
// 拼装'role_menu'表批量插入SQL语句
@@ -196,7 +196,7 @@ func (rm *RoleMenu) Insert(roleId int, menuId []int) (bool, error) {
return false, err
}
// 拼装'casbin_rule'批量插入SQL语句
// 拼装'sys_casbin_rule'批量插入SQL语句
// TODO: casbinRuleQueue队列不为空时才会拼装,否则直接忽略不执行'for'循环
for i, v := range casbinRuleQueue {
casbinRuleSql += fmt.Sprintf("('p','%s','%s','%s')", v.V0, v.V1, v.V2)
@@ -206,7 +206,7 @@ func (rm *RoleMenu) Insert(roleId int, menuId []int) (bool, error) {
casbinRuleSql += ","
}
}
// 执行批量插入casbin_rule
// 执行批量插入sys_casbin_rule
if len(casbinRuleQueue) > 0 {
if err := tx.Exec(casbinRuleSql).Error; err != nil {
tx.Rollback()
+2 -2
View File
@@ -20,12 +20,12 @@ type {{.ClassName}} struct {
{{ range .Columns -}}
{{$x := .Pk}}
{{- if ($x) }}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key;AUTO_INCREMENT;comment:{{.ColumnComment}}"` // {{.ColumnComment}}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key;AUTO_INCREMENT;"` // {{.ColumnComment}}
{{- else if eq .GoField "CreatedAt" -}}
{{- else if eq .GoField "UpdatedAt" -}}
{{- else if eq .GoField "DeletedAt" -}}
{{- else }}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{.ColumnComment}}"` // {{.ColumnComment}}{{end -}}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` {{end -}}
{{- end }}
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
+4 -4
View File
@@ -2,8 +2,8 @@ package models
import (
"strconv"
{{- if eq .IsActions true -}}
{{- else }}
{{- if eq .IsActions 2 -}}
"go-admin/common/dto"
"go-admin/tools"
orm "go-admin/common/global"
@@ -15,12 +15,12 @@ type {{.ClassName}} struct {
{{ range .Columns -}}
{{$x := .Pk}}
{{- if ($x) }}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key;AUTO_INCREMENT;comment:{{.ColumnComment}}"` // {{.ColumnComment}}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key;AUTO_INCREMENT;"`
{{- else if eq .GoField "CreatedAt" -}}
{{- else if eq .GoField "UpdatedAt" -}}
{{- else if eq .GoField "DeletedAt" -}}
{{- else }}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{.ColumnComment}}"` // {{.ColumnComment}}{{end -}}
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` // {{end -}}
{{- end }}
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`