Browse Source

gormv2升级 第一阶段

QM303176530 4 years ago
parent
commit
ba7ae3125b
40 changed files with 133 additions and 99 deletions
  1. 1 1
      server/config.yaml
  2. 14 18
      server/core/install_plugs.go
  3. 1 1
      server/global/global.go
  4. 4 1
      server/go.mod
  5. 24 6
      server/initialize/mysql.go
  6. 1 1
      server/initialize/plug.go
  7. 1 1
      server/initialize/sqlite.go
  8. 2 1
      server/main.go
  9. 2 1
      server/middleware/casbin_rcba.go
  10. 1 1
      server/model/exa_breakpoint_continue.go
  11. 1 1
      server/model/exa_customer.go
  12. 1 1
      server/model/exa_file_upload_download.go
  13. 1 1
      server/model/response/common.go
  14. 1 1
      server/model/sys_api.go
  15. 2 2
      server/model/sys_authority.go
  16. 2 2
      server/model/sys_authority_menu.go
  17. 3 3
      server/model/sys_base_menu.go
  18. 1 1
      server/model/sys_dictionary.go
  19. 8 8
      server/model/sys_dictionary_detail.go
  20. 1 1
      server/model/sys_jwt_blacklist.go
  21. 1 1
      server/model/sys_operation_record.go
  22. 2 2
      server/model/sys_user.go
  23. 1 1
      server/model/sys_workflow.go
  24. 1 1
      server/model/sys_workflow_process.go
  25. 1 1
      server/resource/template/te/model.go.tpl
  26. 1 1
      server/resource/template/te/service.go.tpl
  27. 3 1
      server/service/exa_breakpoint_continue.go
  28. 1 1
      server/service/exa_customer.go
  29. 1 1
      server/service/exa_file_upload_download.go
  30. 4 2
      server/service/exa_simple_uploader.go
  31. 4 2
      server/service/jwt_black_list.go
  32. 5 4
      server/service/sys_api.go
  33. 7 6
      server/service/sys_authority.go
  34. 4 3
      server/service/sys_base_menu.go
  35. 10 6
      server/service/sys_casbin.go
  36. 5 4
      server/service/sys_dictionary.go
  37. 1 1
      server/service/sys_dictionary_detail.go
  38. 4 4
      server/service/sys_menu.go
  39. 2 2
      server/service/sys_operation_record.go
  40. 3 2
      server/service/sys_user.go

+ 1 - 1
server/config.yaml

@@ -17,7 +17,7 @@ mysql:
     config: 'charset=utf8&parseTime=True&loc=Local'
     max-idle-conns: 10
     max-open-conns: 10
-    log-mode: false
+    log-mode: true
 
 #sqlite 配置
 sqlite:

+ 14 - 18
server/core/install_plugs.go

@@ -1,26 +1,22 @@
 package core
 
 import (
-	"fmt"
-	"gin-vue-admin/global"
-	"gin-vue-admin/initialize"
-	"gin-vue-admin/middleware"
 	"github.com/gin-gonic/gin"
-	"github.com/piexlmax/gvaplug"
 )
 
 func InstallPlugs(route *gin.Engine) {
-	GvaPlugsGroupBase := route.Group("") // 纯净路由 插件可通用 传递给插件的0号位置 为了不让插件的自动路由出问题 这里建议为 ""
-	/**安装一个插件需要的步骤 start**/
-	GvaPlugsGroupMiddle := route.Group("") // 携带中间件的路由 传递给插件的1号位置 为了不让插件的自动路由出问题 这里建议为 ""
-	GvaPlugsGroupMiddle.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
-	// 插件安装 暂时只是后台功能 添加model 添加路由 添加对数据库的操作  详细插件测试模板可看https://github.com/piexlmax/gvaplug  此处不建议投入生产
-	err := initialize.InstallPlug(global.GVA_DB, [2]*gin.RouterGroup{
-		GvaPlugsGroupBase,
-		GvaPlugsGroupMiddle,
-	}, gvaplug.GvaPlug{SomeConfig: "插件给用户提供的配置区域"})
-	if err != nil {
-		panic(fmt.Sprintf("插件安装失败: %v", err))
-	}
-	/**安装一个插件需要的步骤 end**/
+	//gorm 升级v2 插件暂时没有升级 插件示例功能暂时不可用
+	//GvaPlugsGroupBase := route.Group("") // 纯净路由 插件可通用 传递给插件的0号位置 为了不让插件的自动路由出问题 这里建议为 ""
+	///**安装一个插件需要的步骤 start**/
+	//GvaPlugsGroupMiddle := route.Group("") // 携带中间件的路由 传递给插件的1号位置 为了不让插件的自动路由出问题 这里建议为 ""
+	//GvaPlugsGroupMiddle.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
+	//// 插件安装 暂时只是后台功能 添加model 添加路由 添加对数据库的操作  详细插件测试模板可看https://github.com/piexlmax/gvaplug  此处不建议投入生产
+	//err := initialize.InstallPlug(global.GVA_DB, [2]*gin.RouterGroup{
+	//	GvaPlugsGroupBase,
+	//	GvaPlugsGroupMiddle,
+	//}, gvaplug.GvaPlug{SomeConfig: "插件给用户提供的配置区域"})
+	//if err != nil {
+	//	panic(fmt.Sprintf("插件安装失败: %v", err))
+	//}
+	///**安装一个插件需要的步骤 end**/
 }

+ 1 - 1
server/global/global.go

@@ -3,9 +3,9 @@ package global
 import (
 	"gin-vue-admin/config"
 	"github.com/go-redis/redis"
-	"github.com/jinzhu/gorm"
 	oplogging "github.com/op/go-logging"
 	"github.com/spf13/viper"
+	"gorm.io/gorm"
 )
 
 var (

+ 4 - 1
server/go.mod

@@ -5,7 +5,9 @@ go 1.12
 require (
 	github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
 	github.com/casbin/casbin v1.9.1
+	github.com/casbin/casbin/v2 v2.11.0
 	github.com/casbin/gorm-adapter v1.0.0
+	github.com/casbin/gorm-adapter/v3 v3.0.2
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
 	github.com/fsnotify/fsnotify v1.4.9
@@ -45,11 +47,12 @@ require (
 	github.com/swaggo/swag v1.6.5
 	github.com/tebeka/strftime v0.1.3 // indirect
 	github.com/unrolled/secure v1.0.7
-	golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 // indirect
 	golang.org/x/net v0.0.0-20200320220750-118fecf932d8 // indirect
 	golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect
 	golang.org/x/tools v0.0.0-20200324003944-a576cf524670 // indirect
 	google.golang.org/protobuf v1.24.0 // indirect
 	gopkg.in/ini.v1 v1.55.0 // indirect
 	gopkg.in/yaml.v2 v2.3.0 // indirect
+	gorm.io/driver/mysql v0.3.1
+	gorm.io/gorm v0.2.35
 )

+ 24 - 6
server/initialize/mysql.go

@@ -2,21 +2,39 @@ package initialize
 
 import (
 	"gin-vue-admin/global"
-	"github.com/jinzhu/gorm"
-	_ "github.com/jinzhu/gorm/dialects/mysql"
+	"gorm.io/driver/mysql"
+	"gorm.io/gorm"
+	"gorm.io/gorm/logger"
 	"os"
 )
 
 // 初始化数据库并产生数据库全局变量
 func Mysql() {
 	admin := global.GVA_CONFIG.Mysql
-	if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil {
+	mysqlConfig := mysql.Config{
+		DSN:                       admin.Username + ":" + admin.Password + "@(" + admin.Path + ")/" + admin.Dbname + "?" + admin.Config, // DSN data source name
+		DefaultStringSize:         256,                                                                                                  // string 类型字段的默认长度
+		DisableDatetimePrecision:  true,                                                                                                 // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
+		DontSupportRenameIndex:    true,                                                                                                 // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
+		DontSupportRenameColumn:   true,                                                                                                 // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
+		SkipInitializeWithVersion: false,                                                                                                // 根据版本自动配置
+	}
+	var gormConfig *gorm.Config
+	if admin.LogMode { //根据配置决定是否开启日志
+		gormConfig = &gorm.Config{
+			Logger: logger.Default.LogMode(logger.Info),
+		}
+	} else {
+		gormConfig = &gorm.Config{}
+	}
+
+	if db, err := gorm.Open(mysql.New(mysqlConfig), gormConfig); err != nil {
 		global.GVA_LOG.Error("MySQL启动异常", err)
 		os.Exit(0)
 	} else {
 		global.GVA_DB = db
-		global.GVA_DB.DB().SetMaxIdleConns(admin.MaxIdleConns)
-		global.GVA_DB.DB().SetMaxOpenConns(admin.MaxOpenConns)
-		global.GVA_DB.LogMode(admin.LogMode)
+		sqlDB, _ := db.DB()
+		sqlDB.SetMaxIdleConns(admin.MaxIdleConns)
+		sqlDB.SetMaxOpenConns(admin.MaxOpenConns)
 	}
 }

+ 1 - 1
server/initialize/plug.go

@@ -2,7 +2,7 @@ package initialize
 
 import (
 	"github.com/gin-gonic/gin"
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 type Plug interface {

+ 1 - 1
server/initialize/sqlite.go

@@ -7,7 +7,7 @@ package initialize
 // import (
 // 	"fmt"
 // 	"gin-vue-admin/global"
-// 	"github.com/jinzhu/gorm"
+// 	"gorm.io/gorm"
 // 	_ "github.com/jinzhu/gorm/dialects/sqlite"
 // )
 //

+ 2 - 1
server/main.go

@@ -25,7 +25,8 @@ func main() {
 	}
 	initialize.DBTables()
 	// 程序结束前关闭数据库链接
-	defer global.GVA_DB.Close()
+	db, _ := global.GVA_DB.DB()
+	defer db.Close()
 
 	core.RunWindowsServer()
 }

+ 2 - 1
server/middleware/casbin_rcba.go

@@ -21,7 +21,8 @@ func CasbinHandler() gin.HandlerFunc {
 		sub := waitUse.AuthorityId
 		e := service.Casbin()
 		// 判断策略中是否存在
-		if global.GVA_CONFIG.System.Env == "develop" || e.Enforce(sub, obj, act) {
+		success, _ := e.Enforce(sub, obj, act)
+		if global.GVA_CONFIG.System.Env == "develop" || success {
 			c.Next()
 		} else {
 			response.Result(response.ERROR, gin.H{}, "权限不足", c)

+ 1 - 1
server/model/exa_breakpoint_continue.go

@@ -1,7 +1,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 // file struct, 文件结构体

+ 1 - 1
server/model/exa_customer.go

@@ -1,7 +1,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 type ExaCustomer struct {

+ 1 - 1
server/model/exa_file_upload_download.go

@@ -1,7 +1,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 type ExaFileUploadAndDownload struct {

+ 1 - 1
server/model/response/common.go

@@ -2,7 +2,7 @@ package response
 
 type PageResult struct {
 	List     interface{} `json:"list"`
-	Total    int         `json:"total"`
+	Total    int64       `json:"total"`
 	Page     int         `json:"page"`
 	PageSize int         `json:"pageSize"`
 }

+ 1 - 1
server/model/sys_api.go

@@ -1,7 +1,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 type SysApi struct {

+ 2 - 2
server/model/sys_authority.go

@@ -11,7 +11,7 @@ type SysAuthority struct {
 	AuthorityId     string         `json:"authorityId" gorm:"not null;unique;primary_key" gorm:"comment:'角色ID'"`
 	AuthorityName   string         `json:"authorityName" gorm:"comment:'角色名'"`
 	ParentId        string         `json:"parentId" gorm:"comment:'父角色ID'"`
-	DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id;association_jointable_foreignkey:data_authority_id"`
-	Children        []SysAuthority `json:"children"`
+	DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"`
+	Children        []SysAuthority `json:"children" gorm:"-"`
 	SysBaseMenus    []SysBaseMenu  `json:"menus" gorm:"many2many:sys_authority_menus;"`
 }

+ 2 - 2
server/model/sys_authority_menu.go

@@ -4,8 +4,8 @@ type SysMenu struct {
 	SysBaseMenu
 	MenuId      string                 `json:"menuId" gorm:"comment:'菜单ID'"`
 	AuthorityId string                 `json:"-" gorm:"comment:'角色ID'"`
-	Children    []SysMenu              `json:"children"`
-	Parameters  []SysBaseMenuParameter `json:"parameters" gorm:"ForeignKey:MenuId"`
+	Children    []SysMenu              `json:"children" gorm:"-"`
+	Parameters  []SysBaseMenuParameter `json:"parameters" gorm:"foreignKey:SysBaseMenuID;references:MenuId"`
 }
 
 func (s SysMenu) TableName() string {

+ 3 - 3
server/model/sys_base_menu.go

@@ -1,7 +1,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 type SysBaseMenu struct {
@@ -15,7 +15,7 @@ type SysBaseMenu struct {
 	Sort          int    `json:"sort" gorm:"comment:'排序标记'"`
 	Meta          `json:"meta" gorm:"comment:'附加属性'"`
 	SysAuthoritys []SysAuthority         `json:"authoritys" gorm:"many2many:sys_authority_menus;"`
-	Children      []SysBaseMenu          `json:"children"`
+	Children      []SysBaseMenu          `json:"children" gorm:"-"`
 	Parameters    []SysBaseMenuParameter `json:"parameters"`
 }
 
@@ -28,7 +28,7 @@ type Meta struct {
 
 type SysBaseMenuParameter struct {
 	gorm.Model
-	SysBaseMenuId uint
+	SysBaseMenuID uint
 	Type          string `json:"type" gorm:"commit:'地址栏携带参数为params还是query'"`
 	Key           string `json:"key" gorm:"commit:'地址栏携带参数的key'"`
 	Value         string `json:"value" gorm:"commit:'地址栏携带参数的值'"`

+ 1 - 1
server/model/sys_dictionary.go

@@ -2,7 +2,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 // 如果含有time.Time 请自行import time包

+ 8 - 8
server/model/sys_dictionary_detail.go

@@ -2,15 +2,15 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 // 如果含有time.Time 请自行import time包
 type SysDictionaryDetail struct {
-      gorm.Model
-      Label  string `json:"label" form:"label" gorm:"column:label;comment:'展示值'"`
-      Value  int `json:"value" form:"value" gorm:"column:value;comment:'字典值'"`
-      Status  *bool `json:"status" form:"status" gorm:"column:status;comment:'启用状态'"`
-      Sort  int `json:"sort" form:"sort" gorm:"column:sort;comment:'排序标记'"`
-      SysDictionaryID  int `json:"sysDictionaryID" form:"sysDictionaryID" gorm:"column:sys_dictionary_id;comment:'关联标记'"` 
-}
+	gorm.Model
+	Label           string `json:"label" form:"label" gorm:"column:label;comment:'展示值'"`
+	Value           int    `json:"value" form:"value" gorm:"column:value;comment:'字典值'"`
+	Status          *bool  `json:"status" form:"status" gorm:"column:status;comment:'启用状态'"`
+	Sort            int    `json:"sort" form:"sort" gorm:"column:sort;comment:'排序标记'"`
+	SysDictionaryID int    `json:"sysDictionaryID" form:"sysDictionaryID" gorm:"column:sys_dictionary_id;comment:'关联标记'"`
+}

+ 1 - 1
server/model/sys_jwt_blacklist.go

@@ -1,7 +1,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 type JwtBlacklist struct {

+ 1 - 1
server/model/sys_operation_record.go

@@ -2,7 +2,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 	"time"
 )
 

+ 2 - 2
server/model/sys_user.go

@@ -1,8 +1,8 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
 	"github.com/satori/go.uuid"
+	"gorm.io/gorm"
 )
 
 type SysUser struct {
@@ -12,6 +12,6 @@ type SysUser struct {
 	Password    string       `json:"-"  gorm:"comment:'用户登录密码'"`
 	NickName    string       `json:"nickName" gorm:"default:'系统用户';comment:'用户昵称'" `
 	HeaderImg   string       `json:"headerImg" gorm:"default:'http://qmplusimg.henrongyi.top/head.png';comment:'用户头像'"`
-	Authority   SysAuthority `json:"authority" gorm:"ForeignKey:AuthorityId;AssociationForeignKey:AuthorityId;comment:'用户角色'"`
+	Authority   SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:'用户角色'"`
 	AuthorityId string       `json:"authorityId" gorm:"default:888;comment:'用户角色ID'"`
 }

+ 1 - 1
server/model/sys_workflow.go

@@ -1,7 +1,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 // 工作流属性表

+ 1 - 1
server/model/sys_workflow_process.go

@@ -1,6 +1,6 @@
 package model
 
-import "github.com/jinzhu/gorm"
+import "gorm.io/gorm"
 
 // 工作流流转表
 type SysWorkFlowProcess struct {

+ 1 - 1
server/resource/template/te/model.go.tpl

@@ -2,7 +2,7 @@
 package model
 
 import (
-	"github.com/jinzhu/gorm"
+	"gorm.io/gorm"
 )
 
 // 如果含有time.Time 请自行import time包

+ 1 - 1
server/resource/template/te/service.go.tpl

@@ -68,7 +68,7 @@ func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructNa
 // @param     info            PageInfo
 // @return                    error
 
-func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int) {
+func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
     // 创建db

+ 3 - 1
server/service/exa_breakpoint_continue.go

@@ -1,8 +1,10 @@
 package service
 
 import (
+	"errors"
 	"gin-vue-admin/global"
 	"gin-vue-admin/model"
+	"gorm.io/gorm"
 )
 
 // @title         FindOrCreateFile
@@ -20,7 +22,7 @@ func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err erro
 	cfile.FileMd5 = fileMd5
 	cfile.FileName = fileName
 	cfile.ChunkTotal = chunkTotal
-	notHaveSameMd5Finish := global.GVA_DB.Where("file_md5 = ? AND is_finish = ?", fileMd5, true).First(&file).RecordNotFound()
+	notHaveSameMd5Finish := errors.Is(global.GVA_DB.Where("file_md5 = ? AND is_finish = ?", fileMd5, true).First(&file).Error, gorm.ErrRecordNotFound)
 	if notHaveSameMd5Finish {
 		err = global.GVA_DB.Where("file_md5 = ? AND file_name = ?", fileMd5, fileName).Preload("ExaFileChunk").FirstOrCreate(&file, cfile).Error
 		return err, file

+ 1 - 1
server/service/exa_customer.go

@@ -58,7 +58,7 @@ func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) {
 // @param     info            PageInfo
 // @return                    error
 
-func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int) {
+func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
 	db := global.GVA_DB.Model(&model.ExaCustomer{})

+ 1 - 1
server/service/exa_file_upload_download.go

@@ -48,7 +48,7 @@ func DeleteFile(file model.ExaFileUploadAndDownload) error {
 // @return    list            error
 // @return    total           error
 
-func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int) {
+func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
 	db := global.GVA_DB

+ 4 - 2
server/service/exa_simple_uploader.go

@@ -1,9 +1,11 @@
 package service
 
 import (
+	"errors"
 	"fmt"
 	"gin-vue-admin/global"
 	"gin-vue-admin/model"
+	"gorm.io/gorm"
 	"io/ioutil"
 	"os"
 	"strconv"
@@ -17,7 +19,7 @@ func SaveChunk(uploader model.ExaSimpleUploader) (err error) {
 // 检查文件是否已经上传过
 func CheckFileMd5(md5 string) (err error, uploads []model.ExaSimpleUploader, isDone bool) {
 	err = global.GVA_DB.Find(&uploads, "identifier = ? AND is_done = ?", md5, false).Error
-	isDone = global.GVA_DB.First(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, true).RecordNotFound()
+	isDone = errors.Is(global.GVA_DB.First(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, true).Error, gorm.ErrRecordNotFound)
 	return err, uploads, !isDone
 }
 
@@ -26,7 +28,7 @@ func MergeFileMd5(md5 string, fileName string) (err error) {
 	finishDir := "./finish/"
 	dir := "./chunk/" + md5
 	//如果文件上传成功 不做后续操作 通知成功即可
-	notFinish := global.GVA_DB.First(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, true).RecordNotFound()
+	notFinish := errors.Is(global.GVA_DB.First(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, true).Error, gorm.ErrRecordNotFound)
 	if !notFinish {
 		return nil
 	}

+ 4 - 2
server/service/jwt_black_list.go

@@ -1,8 +1,10 @@
 package service
 
 import (
+	"errors"
 	"gin-vue-admin/global"
 	"gin-vue-admin/model"
+	"gorm.io/gorm"
 	"time"
 )
 
@@ -25,7 +27,7 @@ func JsonInBlacklist(jwtList model.JwtBlacklist) (err error) {
 // @return    err             error
 
 func IsBlacklist(jwt string) bool {
-	isNotFound := global.GVA_DB.Where("jwt = ?", jwt).First(&model.JwtBlacklist{}).RecordNotFound()
+	isNotFound := errors.Is(global.GVA_DB.Where("jwt = ?", jwt).First(&model.JwtBlacklist{}).Error, gorm.ErrRecordNotFound)
 	return !isNotFound
 }
 
@@ -50,7 +52,7 @@ func GetRedisJWT(userName string) (err error, redisJWT string) {
 
 func SetRedisJWT(jwt string, userName string) (err error) {
 	// 此处过期时间等于jwt过期时间
-	timer := 60*60*24*7*time.Second
+	timer := 60 * 60 * 24 * 7 * time.Second
 	err = global.GVA_REDIS.Set(userName, jwt, timer).Err()
 	return err
 }

+ 5 - 4
server/service/sys_api.go

@@ -5,6 +5,7 @@ import (
 	"gin-vue-admin/global"
 	"gin-vue-admin/model"
 	"gin-vue-admin/model/request"
+	"gorm.io/gorm"
 )
 
 // @title    CreateApi
@@ -46,7 +47,7 @@ func DeleteApi(api model.SysApi) (err error) {
 // @return    list            interface{}
 // @return    total           int
 
-func GetAPIInfoList(api model.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int) {
+func GetAPIInfoList(api model.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
 	db := global.GVA_DB.Model(&model.SysApi{})
@@ -81,9 +82,9 @@ func GetAPIInfoList(api model.SysApi, info request.PageInfo, order string, desc
 			} else {
 				OrderStr = order
 			}
-			err = db.Order(OrderStr, true).Find(&apiList).Error
+			err = db.Order(OrderStr).Find(&apiList).Error
 		} else {
-			err = db.Order("api_group", true).Find(&apiList).Error
+			err = db.Order("api_group").Find(&apiList).Error
 		}
 	}
 	return err, apiList, total
@@ -124,7 +125,7 @@ func UpdateApi(api model.SysApi) (err error) {
 	err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error
 
 	if oldA.Path != api.Path || oldA.Method != api.Method {
-		flag := global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).Find(&model.SysApi{}).RecordNotFound()
+		flag := errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).Find(&model.SysApi{}).Error, gorm.ErrRecordNotFound)
 		if !flag {
 			return errors.New("存在相同api路径")
 		}

+ 7 - 6
server/service/sys_authority.go

@@ -6,6 +6,7 @@ import (
 	"gin-vue-admin/model"
 	"gin-vue-admin/model/request"
 	"gin-vue-admin/model/response"
+	"gorm.io/gorm"
 	"strconv"
 )
 
@@ -18,7 +19,7 @@ import (
 
 func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAuthority) {
 	var authorityBox model.SysAuthority
-	notHas := global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).Find(&authorityBox).RecordNotFound()
+	notHas := errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).Find(&authorityBox).Error, gorm.ErrRecordNotFound)
 	if !notHas {
 		return errors.New("存在相同角色id"), auth
 	}
@@ -35,7 +36,7 @@ func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAut
 
 func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority model.SysAuthority) {
 	var authorityBox model.SysAuthority
-	notHas := global.GVA_DB.Where("authority_id = ?", copyInfo.Authority.AuthorityId).Find(&authorityBox).RecordNotFound()
+	notHas := errors.Is(global.GVA_DB.Where("authority_id = ?", copyInfo.Authority.AuthorityId).Find(&authorityBox).Error, gorm.ErrRecordNotFound)
 	if !notHas {
 		return errors.New("存在相同角色id"), authority
 	}
@@ -90,7 +91,7 @@ func DeleteAuthority(auth *model.SysAuthority) (err error) {
 	}
 	db := global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", auth.AuthorityId).First(auth).Unscoped().Delete(auth)
 	if len(auth.SysBaseMenus) > 0 {
-		err = db.Association("SysBaseMenus").Delete(auth.SysBaseMenus).Error
+		err = db.Association("SysBaseMenus").Delete(auth.SysBaseMenus)
 	} else {
 		err = db.Error
 	}
@@ -105,7 +106,7 @@ func DeleteAuthority(auth *model.SysAuthority) (err error) {
 // @return                    error
 // 分页获取数据
 
-func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int) {
+func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
 	db := global.GVA_DB
@@ -140,7 +141,7 @@ func GetAuthorityInfo(auth model.SysAuthority) (err error, sa model.SysAuthority
 func SetDataAuthority(auth model.SysAuthority) error {
 	var s model.SysAuthority
 	global.GVA_DB.Preload("DataAuthorityId").First(&s, "authority_id = ?", auth.AuthorityId)
-	err := global.GVA_DB.Model(&s).Association("DataAuthorityId").Replace(&auth.DataAuthorityId).Error
+	err := global.GVA_DB.Model(&s).Association("DataAuthorityId").Replace(&auth.DataAuthorityId)
 	return err
 }
 
@@ -153,7 +154,7 @@ func SetDataAuthority(auth model.SysAuthority) error {
 func SetMenuAuthority(auth *model.SysAuthority) error {
 	var s model.SysAuthority
 	global.GVA_DB.Preload("SysBaseMenus").First(&s, "authority_id = ?", auth.AuthorityId)
-	err := global.GVA_DB.Model(&s).Association("SysBaseMenus").Replace(&auth.SysBaseMenus).Error
+	err := global.GVA_DB.Model(&s).Association("SysBaseMenus").Replace(&auth.SysBaseMenus)
 	return err
 }
 

+ 4 - 3
server/service/sys_base_menu.go

@@ -4,6 +4,7 @@ import (
 	"errors"
 	"gin-vue-admin/global"
 	"gin-vue-admin/model"
+	"gorm.io/gorm"
 )
 
 // @title    DeleteBaseMenu
@@ -19,7 +20,7 @@ func DeleteBaseMenu(id float64) (err error) {
 		db := global.GVA_DB.Preload("SysAuthoritys").Where("id = ?", id).First(&menu).Delete(&menu)
 		err = global.GVA_DB.Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", id).Error
 		if len(menu.SysAuthoritys) > 0 {
-			err = db.Association("SysAuthoritys").Delete(menu.SysAuthoritys).Error
+			err = db.Association("SysAuthoritys").Delete(menu.SysAuthoritys)
 		} else {
 			err = db.Error
 		}
@@ -51,13 +52,13 @@ func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
 
 	db := global.GVA_DB.Where("id = ?", menu.ID).Find(&oldMenu)
 	if oldMenu.Name != menu.Name {
-		notSame := global.GVA_DB.Where("id <> ? AND name = ?", menu.ID, menu.Name).First(&model.SysBaseMenu{}).RecordNotFound()
+		notSame := errors.Is(global.GVA_DB.Where("id <> ? AND name = ?", menu.ID, menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound)
 		if !notSame {
 			global.GVA_LOG.Debug("存在相同name修改失败")
 			return errors.New("存在相同name修改失败")
 		}
 	}
-	err = db.Updates(upDateMap).Association("Parameters").Replace(menu.Parameters).Error
+	err = db.Updates(upDateMap).Association("Parameters").Replace(menu.Parameters)
 	global.GVA_LOG.Debug("菜单修改时候,关联菜单err:%v", err)
 	return err
 }

+ 10 - 6
server/service/sys_casbin.go

@@ -5,9 +5,10 @@ import (
 	"gin-vue-admin/global"
 	"gin-vue-admin/model"
 	"gin-vue-admin/model/request"
-	"github.com/casbin/casbin"
 	"github.com/casbin/casbin/util"
-	gormadapter "github.com/casbin/gorm-adapter"
+	"github.com/casbin/casbin/v2"
+	gormadapter "github.com/casbin/gorm-adapter/v3"
+	_ "github.com/go-sql-driver/mysql"
 	"strings"
 )
 
@@ -44,7 +45,8 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
 
 func AddCasbin(cm model.CasbinModel) bool {
 	e := Casbin()
-	return e.AddPolicy(cm.AuthorityId, cm.Path, cm.Method)
+	success, _ := e.AddPolicy(cm.AuthorityId, cm.Path, cm.Method)
+	return success
 }
 
 // @title    UpdateCasbinApi
@@ -92,7 +94,8 @@ func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinIn
 
 func ClearCasbin(v int, p ...string) bool {
 	e := Casbin()
-	return e.RemoveFilteredPolicy(v, p...)
+	success, _ := e.RemoveFilteredPolicy(v, p...)
+	return success
 
 }
 
@@ -101,8 +104,9 @@ func ClearCasbin(v int, p ...string) bool {
 // @auth                     (2020/04/05  20:22)
 
 func Casbin() *casbin.Enforcer {
-	a := gormadapter.NewAdapterByDB(global.GVA_DB)
-	e := casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a)
+	admin := global.GVA_CONFIG.Mysql
+	a, _ := gormadapter.NewAdapter(global.GVA_CONFIG.System.DbType, admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname, true)
+	e, _ := casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a)
 	e.AddFunction("ParamsMatch", ParamsMatchFunc)
 	_ = e.LoadPolicy()
 	return e

+ 5 - 4
server/service/sys_dictionary.go

@@ -5,6 +5,7 @@ import (
 	"gin-vue-admin/global"
 	"gin-vue-admin/model"
 	"gin-vue-admin/model/request"
+	"gorm.io/gorm"
 )
 
 // @title    CreateSysDictionary
@@ -14,7 +15,7 @@ import (
 // @return    err             error
 
 func CreateSysDictionary(sysDictionary model.SysDictionary) (err error) {
-	if (!global.GVA_DB.First(&model.SysDictionary{}, "type = ?", sysDictionary.Type).RecordNotFound()) {
+	if (!errors.Is(global.GVA_DB.First(&model.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) {
 		return errors.New("存在相同的type,不允许创建")
 	}
 	err = global.GVA_DB.Create(&sysDictionary).Error
@@ -28,7 +29,7 @@ func CreateSysDictionary(sysDictionary model.SysDictionary) (err error) {
 // @return                    error
 
 func DeleteSysDictionary(sysDictionary model.SysDictionary) (err error) {
-	err = global.GVA_DB.Delete(sysDictionary).Related(&sysDictionary.SysDictionaryDetails).Delete(&sysDictionary.SysDictionaryDetails).Error
+	err = global.GVA_DB.Delete(sysDictionary).Delete(&sysDictionary.SysDictionaryDetails).Error
 	return err
 }
 
@@ -50,7 +51,7 @@ func UpdateSysDictionary(sysDictionary *model.SysDictionary) (err error) {
 	if dict.Type == sysDictionary.Type {
 		err = db.Updates(sysDictionaryMap).Error
 	} else {
-		if (!global.GVA_DB.First(&model.SysDictionary{}, "type = ?", sysDictionary.Type).RecordNotFound()) {
+		if (!errors.Is(global.GVA_DB.First(&model.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) {
 			return errors.New("存在相同的type,不允许创建")
 		} else {
 			err = db.Updates(sysDictionaryMap).Error
@@ -77,7 +78,7 @@ func GetSysDictionary(Type string, Id uint) (err error, sysDictionary model.SysD
 // @param     info            PageInfo
 // @return                    error
 
-func GetSysDictionaryInfoList(info request.SysDictionarySearch) (err error, list interface{}, total int) {
+func GetSysDictionaryInfoList(info request.SysDictionarySearch) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
 	// 创建db

+ 1 - 1
server/service/sys_dictionary_detail.go

@@ -57,7 +57,7 @@ func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail model.SysDi
 // @param     info            PageInfo
 // @return                    error
 
-func GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int) {
+func GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
 	// 创建db

+ 4 - 4
server/service/sys_menu.go

@@ -16,7 +16,7 @@ import (
 func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]model.SysMenu) {
 	var allMenus []model.SysMenu
 	treeMap = make(map[string][]model.SysMenu)
-	err = global.GVA_DB.Where("authority_id = ?", authorityId).Order("sort", true).Preload("Parameters").Find(&allMenus).Error
+	err = global.GVA_DB.Where("authority_id = ?", authorityId).Order("sort").Preload("Parameters").Find(&allMenus).Error
 	for _, v := range allMenus {
 		treeMap[v.ParentId] = append(treeMap[v.ParentId], v)
 	}
@@ -62,7 +62,7 @@ func getChildrenList(menu *model.SysMenu, treeMap map[string][]model.SysMenu) (e
 // @return    list            interface{}
 // @return    total           int
 
-func GetInfoList() (err error, list interface{}, total int) {
+func GetInfoList() (err error, list interface{}, total int64) {
 	var menuList []model.SysBaseMenu
 	err, treeMap := getBaseMenuTreeMap()
 	menuList = treeMap["0"]
@@ -112,7 +112,7 @@ func AddBaseMenu(menu model.SysBaseMenu) (err error) {
 func getBaseMenuTreeMap() (err error, treeMap map[string][]model.SysBaseMenu) {
 	var allMenus []model.SysBaseMenu
 	treeMap = make(map[string][]model.SysBaseMenu)
-	err = global.GVA_DB.Order("sort", true).Preload("Parameters").Find(&allMenus).Error
+	err = global.GVA_DB.Order("sort").Preload("Parameters").Find(&allMenus).Error
 	for _, v := range allMenus {
 		treeMap[v.ParentId] = append(treeMap[v.ParentId], v)
 	}
@@ -158,7 +158,7 @@ func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error)
 
 func GetMenuAuthority(authorityId string) (err error, menus []model.SysMenu) {
 	//sql := "SELECT authority_menu.keep_alive,authority_menu.default_menu,authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? ORDER BY authority_menu.sort ASC"
-	err = global.GVA_DB.Order("sort", true).Find(&menus).Error
+	err = global.GVA_DB.Order("sort").Find(&menus).Error
 	//err = global.GVA_DB.Raw(sql, authorityId).Scan(&menus).Error
 	return err, menus
 }

+ 2 - 2
server/service/sys_operation_record.go

@@ -24,7 +24,7 @@ func CreateSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err
 // @return                    error
 
 func DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
-	err = global.GVA_DB.Delete(&[]model.SysOperationRecord{},"id in (?)",ids.Ids).Error
+	err = global.GVA_DB.Delete(&[]model.SysOperationRecord{}, "id in (?)", ids.Ids).Error
 	return err
 }
 
@@ -68,7 +68,7 @@ func GetSysOperationRecord(id uint) (err error, sysOperationRecord model.SysOper
 // @param     info            PageInfo
 // @return                    error
 
-func GetSysOperationRecordInfoList(info request.SysOperationRecordSearch) (err error, list interface{}, total int) {
+func GetSysOperationRecordInfoList(info request.SysOperationRecordSearch) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
 	// 创建db

+ 3 - 2
server/service/sys_user.go

@@ -7,6 +7,7 @@ import (
 	"gin-vue-admin/model/request"
 	"gin-vue-admin/utils"
 	uuid "github.com/satori/go.uuid"
+	"gorm.io/gorm"
 )
 
 // @title    Register
@@ -19,7 +20,7 @@ import (
 func Register(u model.SysUser) (err error, userInter model.SysUser) {
 	var user model.SysUser
 	// 判断用户名是否注册
-	notRegister := global.GVA_DB.Where("username = ?", u.Username).First(&user).RecordNotFound()
+	notRegister := errors.Is(global.GVA_DB.Where("username = ?", u.Username).First(&user).Error, gorm.ErrRecordNotFound)
 	// notRegister为false表明读取到了 不能注册
 	if !notRegister {
 		return errors.New("用户名已注册"), userInter
@@ -69,7 +70,7 @@ func ChangePassword(u *model.SysUser, newPassword string) (err error, userInter
 // @return    list             interface{}
 // @return    total            int
 
-func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total int) {
+func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
 	db := global.GVA_DB.Model(&model.SysUser{})