fix:优化代码

This commit is contained in:
zhangwenjian committed 2021-02-19 10:48:27 +08:00
1 parent 981e992f28
commit 9186c6ce04
5 files changed
+62 -12

No files matched your search

+2 -3
View File
@@ -2,10 +2,9 @@ package models
import (
"errors"
"fmt"
"gorm.io/gorm"
"go-admin/common/log"
"go-admin/tools"
"go-admin/tools/config"
)
@@ -21,7 +20,7 @@ func (e *DataPermission) GetDataScope(tbname string, table *gorm.DB) (*gorm.DB,
if !config.ApplicationConfig.EnableDP {
usageStr := `数据权限已经为您` + tools.Green(`关闭`) + `,如需开启请参考配置文件字段说明`
fmt.Printf("%s\n", usageStr)
log.Debug("%s\n", usageStr)
return table, nil
}
SysUser := new(SysUser)
@@ -24,13 +24,13 @@ func _1599190683659Tables(db *gorm.DB, version string) error {
new(system.SysConfig),
new(tools.SysTables),
new(tools.SysColumns),
new(models.Menu),
new(models.SysMenu),
new(system.SysLoginLog),
new(system.SysOperaLog),
new(models.RoleMenu),
new(models.SysRoleDept),
new(models.SysUser),
new(models.SysRole),
new(system.SysRole),
new(models.Post),
new(models.DictData),
new(models.DictType),
@@ -20,7 +20,7 @@ func _1600089797118Migrate(db *gorm.DB, version string) error {
f := &models.SysFileDir{
Label: "根目录",
PId: 0,
//Sort: "0",
Sort: "0",
Path: "",
ControlBy: common.ControlBy{
CreateBy: 1,
@@ -0,0 +1,50 @@
package version
import (
"go-admin/app/admin/models"
"go-admin/app/admin/models/system"
//"go-admin/app/admin/models"
"gorm.io/gorm"
"runtime"
"go-admin/cmd/migrate/migration"
common "go-admin/common/models"
)
func init() {
_, fileName, _, _ := runtime.Caller(0)
migration.Migrate.SetVersion(migration.GetFilename(fileName), _1613638159444Test)
}
func _1613638159444Test(db *gorm.DB, version string) error {
return db.Transaction(func(tx *gorm.DB) error {
// TODO: 这里开始写入要变更的内容
// TODO: 例如 修改表字段 使用过程中请删除此段代码
err := tx.Migrator().AlterColumn(&system.SysRole{}, "create_by")
if err != nil {
return err
}
err = tx.Migrator().AlterColumn(&system.SysRole{}, "update_by")
if err != nil {
return err
}
err = tx.Migrator().AlterColumn(&models.SysMenu{}, "update_by")
if err != nil {
return err
}
err = tx.Migrator().AlterColumn(&models.SysMenu{}, "create_by")
if err != nil {
return err
}
return tx.Create(&common.Migration{
Version: version,
}).Error
})
}
+7 -6
View File
@@ -3,8 +3,8 @@ package models
import "time"
type ControlBy struct {
CreateBy int `gorm:"index;comment:'创建者'"`
UpdateBy int `gorm:"index;comment:'更新者'"`
CreateBy int `json:"createBy" gorm:"index;comment:创建者"`
UpdateBy int `json:"updateBy" gorm:"index;comment:更新者"`
}
func (e *ControlBy) SetCreateBy(createBy int) {
@@ -17,11 +17,12 @@ func (e *ControlBy) SetUpdateBy(updateBy int) {
type Model struct {
ID int `gorm:"primaryKey;autoIncrement;comment:'主键编码'"`
ID int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码"`
}
type ModelTime struct {
CreatedAt time.Time `gorm:"comment:'创建时间'"`
UpdatedAt time.Time `gorm:"comment:'最后更新时间'"`
DeletedAt *time.Time `gorm:"index;comment:'删除时间'"`
CreatedAt time.Time `json:"createdAt" gorm:"comment:创建时间"`
UpdatedAt time.Time `json:"updatedAt" gorm:"comment:最后更新时间"`
DeletedAt *time.Time `json:"-" gorm:"index;comment:删除时间"`
}